o
    h%                     @  s   d Z ddlmZ ddlZddlZddlmZmZmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZmZ G d
d dZdS )zRepresent one server the driver is connected to.

.. seealso:: This module is compatible with both the synchronous and asynchronous PyMongo APIs.
    )annotationsN)AnyMappingOptional)EPOCH_NAIVE)ObjectId)Hello)SERVER_TYPE)ClusterTime_Addressc                   @  s  e Zd ZU dZdZ				dgdhddZediddZedjddZedkddZ	edlddZ
edmdd Zednd"d#Zedod%d&Zedjd'd(Zedjd)d*Zedjd+d,Zedjd-d.Zedjd/d0Zedpd2d3Zedqd5d6Zedrd8d9Zedsd;d<Zedod=d>Zedpd?d@ZedtdAdBZedudCdDZedtdEdFZedudGdHZedvdIdJZedwdLdMZedwdNdOZedwdPdQZ edwdRdSZ!edwdTdUZ"edwdVdWZ#edxdYdZZ$dydzd[d\Z%d{d_d`Z&d{dadbZ'dkdcddZ(i Z)dee*df< dS )|ServerDescriptionaR  Immutable representation of one server.

    :param address: A (host, port) pair
    :param hello: Optional Hello instance
    :param round_trip_time: Optional float
    :param error: Optional, the last error attempting to connect to the server
    :param round_trip_time: Optional float, the min latency from the most recent samples
    )_address_server_type
_all_hosts_tags_replica_set_name_primary_max_bson_size_max_message_size_max_write_batch_size_min_wire_version_max_wire_version_round_trip_time_min_round_trip_time_me_is_writable_is_readable_ls_timeout_minutes_error_set_version_election_id_cluster_time_last_write_date_last_update_time_topology_versionN        addressr   helloOptional[Hello]round_trip_timeOptional[float]errorOptional[Exception]min_round_trip_timefloatreturnNonec                 C  s  || _ |s	ti }|j| _|j| _|j| _|j| _	|j
| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j | _!|| _"|| _#|j$| _%t&' | _(|| _)|j*| _+|rrt,|dd }t-|t.rr|/d| _+|  |j0r|j0t1 }|2 | _3d S d | _3d S )NdetailsZtopologyVersion)4r   r   server_typer   	all_hostsr   tagsr   replica_set_namer   primaryr   max_bson_sizer   max_message_sizer   max_write_batch_sizer   min_wire_versionr   max_wire_versionr   set_versionr   election_idr    cluster_timer!   is_writabler   is_readabler   logical_session_timeout_minutesr   r   r   mer   time	monotonicr#   r   topology_versionr$   getattr
isinstancedictgetlast_write_dater   total_secondsr"   )selfr&   r'   r)   r+   r-   r1   delta rN   M/var/www/html/venv/lib/python3.10/site-packages/pymongo/server_description.py__init__E   sD   



zServerDescription.__init__c                 C     | j S )z(The address (host, port) of this server.)r   rL   rN   rN   rO   r&   t      zServerDescription.addressintc                 C  rQ   )zThe type of this server.)r   rR   rN   rN   rO   r2   y   rS   zServerDescription.server_typestrc                 C  s   t j| j S )zSThe server type as a human readable string.

        .. versionadded:: 3.4
        )r	   _fieldsr   rR   rN   rN   rO   server_type_name~   s   z"ServerDescription.server_type_nameset[tuple[str, int]]c                 C  rQ   )z;List of hosts, passives, and arbiters known to this server.)r   rR   rN   rN   rO   r3      rS   zServerDescription.all_hostsMapping[str, Any]c                 C  rQ   N)r   rR   rN   rN   rO   r4         zServerDescription.tagsOptional[str]c                 C  rQ   )zReplica set name or None.)r   rR   rN   rN   rO   r5      rS   z"ServerDescription.replica_set_nameOptional[tuple[str, int]]c                 C  rQ   )z8This server's opinion about who the primary is, or None.)r   rR   rN   rN   rO   r6      rS   zServerDescription.primaryc                 C  rQ   rZ   )r   rR   rN   rN   rO   r7      r[   zServerDescription.max_bson_sizec                 C  rQ   rZ   )r   rR   rN   rN   rO   r8      r[   z"ServerDescription.max_message_sizec                 C  rQ   rZ   )r   rR   rN   rN   rO   r9      r[   z&ServerDescription.max_write_batch_sizec                 C  rQ   rZ   )r   rR   rN   rN   rO   r:      r[   z"ServerDescription.min_wire_versionc                 C  rQ   rZ   r   rR   rN   rN   rO   r;      r[   z"ServerDescription.max_wire_versionOptional[int]c                 C  rQ   rZ   )r   rR   rN   rN   rO   r<      r[   zServerDescription.set_versionOptional[ObjectId]c                 C  rQ   rZ   )r    rR   rN   rN   rO   r=      r[   zServerDescription.election_idOptional[ClusterTime]c                 C  rQ   rZ   )r!   rR   rN   rN   rO   r>      r[   zServerDescription.cluster_time(tuple[Optional[int], Optional[ObjectId]]c                 C  s   t jdtdd | j| jfS )NzL'election_tuple' is deprecated, use  'set_version' and 'election_id' instead   )
stacklevel)warningswarnDeprecationWarningr   r    rR   rN   rN   rO   election_tuple   s   z ServerDescription.election_tuplec                 C  rQ   rZ   )r   rR   rN   rN   rO   rB      r[   zServerDescription.mec                 C  rQ   rZ   )r   rR   rN   rN   rO   rA      r[   z1ServerDescription.logical_session_timeout_minutesc                 C  rQ   rZ   )r"   rR   rN   rN   rO   rJ      r[   z!ServerDescription.last_write_datec                 C  rQ   rZ   )r#   rR   rN   rN   rO   last_update_time   r[   z"ServerDescription.last_update_timec                 C  s   | j | jv r| j| j  S | jS )z$The current average latency or None.)r   _host_to_round_trip_timer   rR   rN   rN   rO   r)      s   z!ServerDescription.round_trip_timec                 C  rQ   )z-The min latency from the most recent samples.)r   rR   rN   rN   rO   r-      rS   z%ServerDescription.min_round_trip_timec                 C  rQ   )z<The last error attempting to connect to the server, or None.)r   rR   rN   rN   rO   r+      rS   zServerDescription.errorboolc                 C  rQ   rZ   )r   rR   rN   rN   rO   r?      r[   zServerDescription.is_writablec                 C  rQ   rZ   )r   rR   rN   rN   rO   r@      r[   zServerDescription.is_readablec                 C  s   | j tjkS rZ   )r   r	   MongosrR   rN   rN   rO   mongos      zServerDescription.mongosc                 C  s   | j tjkS rZ   )r2   r	   UnknownrR   rN   rN   rO   is_server_type_known   rn   z&ServerDescription.is_server_type_knownc                 C  s   | j tjtjfv p| j tjkS )0Checks if this server supports retryable writes.)r   r	   rl   Z	RSPrimaryZLoadBalancerrR   rN   rN   rO   retryable_writes_supported   s   
z,ServerDescription.retryable_writes_supportedc                 C  s
   | j dkS )rq      r^   rR   rN   rN   rO   retryable_reads_supported   s   
z+ServerDescription.retryable_reads_supportedOptional[Mapping[str, Any]]c                 C  rQ   rZ   )r$   rR   rN   rN   rO   rE     r[   z"ServerDescription.topology_versionc                 C  s   t | j|d}| j|_|S )N)r+   )r   r&   rE   r$   )rL   r+   unknownrN   rN   rO   
to_unknown  s   zServerDescription.to_unknownotherr   c                 C  s   t |trS| j|jkoR| j|jkoR| j|jkoR| j|j	koR| j
|jkoR| j|jkoR| j|jkoR| j|jkoR| j|jkoR| j|jkoR| j|jkoR| j|jkoR| j|jkS tS rZ   )rG   r   r   r&   r   r2   r   r:   r   r;   r   rB   r   r3   r   r4   r   r5   r   r<   r    r=   r   r6   r   rA   r   r+   NotImplementedrL   rx   rN   rN   rO   __eq__
  s6   









	



zServerDescription.__eq__c                 C  s
   | |k S rZ   rN   rz   rN   rN   rO   __ne__  s   
zServerDescription.__ne__c                 C  s2   d}| j rd| j }d| jj| j| j| j|S )N z, error=z"<{} {} server_type: {}, rtt: {}{}>)r+   format	__class____name__r&   rW   r)   )rL   errmsgrN   rN   rO   __repr__!  s   zServerDescription.__repr__rH   rj   )NNNr%   )r&   r   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   )r/   r   )r/   rT   )r/   rU   )r/   rX   )r/   rY   )r/   r\   )r/   r]   )r/   r_   )r/   r`   )r/   ra   )r/   rb   )r/   r*   )r/   r.   )r/   r,   )r/   rk   )r/   ru   rZ   )r+   r,   r/   r   )rx   r   r/   rk   )+r   
__module____qualname____doc__	__slots__rP   propertyr&   r2   rW   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   rh   rB   rA   rJ   ri   r)   r-   r+   r?   r@   rm   rp   rr   rt   rE   rw   r{   r|   r   rj   __annotations__rN   rN   rN   rO   r       s   
 	/


r   )r   
__future__r   rC   re   typingr   r   r   Zbsonr   Zbson.objectidr   Zpymongo.hellor   Zpymongo.server_typer	   Zpymongo.typingsr
   r   r   rN   rN   rN   rO   <module>   s   