U
    ~fh%                     @  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ddddddd	d
dddZeddddZeddddZeddddZ	eddddZ
eddddZeddddZed dd!d"Zeddd#d$Zeddd%d&Zeddd'd(Zeddd)d*Zeddd+d,Zed-dd.d/Zed0dd1d2Zed3dd4d5Zed6dd7d8Zed dd9d:Zed-dd;d<Zeddd=d>Zed	dd?d@ZedddAdBZed	ddCdDZedddEdFZedGddHdIZedGddJdKZedGddLdMZ edGddNdOZ!edGddPdQZ"edGddRdSZ#edTddUdVZ$dedd dWdXdYZ%dZdGd[d\d]Z&dZdGd[d^d_Z'ddd`daZ(i Z)dbe*dc< dS )f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        r   zOptional[Hello]zOptional[float]zOptional[Exception]floatNone)addresshelloround_trip_timeerrormin_round_trip_timereturnc                 C  s  || _ |sti }|j| _|j| _|j| _|j| _	|j
| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j | _!|| _"|| _#|j$| _%t&' | _(|| _)|j*| _+|rt,|dd }t-|t.r|/d| _+|  |j0r|j0t1 }|2 | _3n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,   r.   delta rK   >/tmp/pip-unpacked-wheel-36gvocj8/pymongo/server_description.py__init__E   sD    


zServerDescription.__init__)r-   c                 C  s   | j S )z(The address (host, port) of this server.)r   rI   rK   rK   rL   r(   t   s    zServerDescription.addressintc                 C  s   | j S )zThe type of this server.)r   rN   rK   rK   rL   r/   y   s    zServerDescription.server_typestrc                 C  s   t j| j S )zSThe server type as a human readable string.

        .. versionadded:: 3.4
        )r	   _fieldsr   rN   rK   rK   rL   server_type_name~   s    z"ServerDescription.server_type_namezset[tuple[str, int]]c                 C  s   | j S )z;List of hosts, passives, and arbiters known to this server.)r   rN   rK   rK   rL   r0      s    zServerDescription.all_hostszMapping[str, Any]c                 C  s   | j S N)r   rN   rK   rK   rL   r1      s    zServerDescription.tagszOptional[str]c                 C  s   | j S )zReplica set name or None.)r   rN   rK   rK   rL   r2      s    z"ServerDescription.replica_set_namezOptional[tuple[str, int]]c                 C  s   | j S )z8This server's opinion about who the primary is, or None.)r   rN   rK   rK   rL   r3      s    zServerDescription.primaryc                 C  s   | j S rS   )r   rN   rK   rK   rL   r4      s    zServerDescription.max_bson_sizec                 C  s   | j S rS   )r   rN   rK   rK   rL   r5      s    z"ServerDescription.max_message_sizec                 C  s   | j S rS   )r   rN   rK   rK   rL   r6      s    z&ServerDescription.max_write_batch_sizec                 C  s   | j S rS   )r   rN   rK   rK   rL   r7      s    z"ServerDescription.min_wire_versionc                 C  s   | j S rS   r   rN   rK   rK   rL   r8      s    z"ServerDescription.max_wire_versionzOptional[int]c                 C  s   | j S rS   )r   rN   rK   rK   rL   r9      s    zServerDescription.set_versionzOptional[ObjectId]c                 C  s   | j S rS   )r    rN   rK   rK   rL   r:      s    zServerDescription.election_idzOptional[ClusterTime]c                 C  s   | j S rS   )r!   rN   rK   rK   rL   r;      s    zServerDescription.cluster_timez(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    rN   rK   rK   rL   election_tuple   s    z ServerDescription.election_tuplec                 C  s   | j S rS   )r   rN   rK   rK   rL   r?      s    zServerDescription.mec                 C  s   | j S rS   )r   rN   rK   rK   rL   r>      s    z1ServerDescription.logical_session_timeout_minutesc                 C  s   | j S rS   )r"   rN   rK   rK   rL   rG      s    z!ServerDescription.last_write_datec                 C  s   | j S rS   )r#   rN   rK   rK   rL   last_update_time   s    z"ServerDescription.last_update_timec                 C  s   | j | jkr| j| j  S | jS )z$The current average latency or None.)r   _host_to_round_trip_timer   rN   rK   rK   rL   r*      s    z!ServerDescription.round_trip_timec                 C  s   | j S )z-The min latency from the most recent samples.)r   rN   rK   rK   rL   r,      s    z%ServerDescription.min_round_trip_timec                 C  s   | j S )z<The last error attempting to connect to the server, or None.)r   rN   rK   rK   rL   r+      s    zServerDescription.errorboolc                 C  s   | j S rS   )r   rN   rK   rK   rL   r<      s    zServerDescription.is_writablec                 C  s   | j S rS   )r   rN   rK   rK   rL   r=      s    zServerDescription.is_readablec                 C  s   | j tjkS rS   )r   r	   MongosrN   rK   rK   rL   mongos   s    zServerDescription.mongosc                 C  s   | j tjkS rS   )r/   r	   UnknownrN   rK   rK   rL   is_server_type_known   s    z&ServerDescription.is_server_type_knownc                 C  s   | j tjtjfkp| j tjkS )0Checks if this server supports retryable writes.)r   r	   r^   Z	RSPrimaryZLoadBalancerrN   rK   rK   rL   retryable_writes_supported   s    
z,ServerDescription.retryable_writes_supportedc                 C  s
   | j dkS )rb      rT   rN   rK   rK   rL   retryable_reads_supported   s    z+ServerDescription.retryable_reads_supportedzOptional[Mapping[str, Any]]c                 C  s   | j S rS   )r$   rN   rK   rK   rL   rB     s    z"ServerDescription.topology_version)r+   r-   c                 C  s   t | j|d}| j|_|S )N)r+   )r   r(   rB   r$   )rI   r+   unknownrK   rK   rL   
to_unknown  s    zServerDescription.to_unknownr   )otherr-   c                 C  s   t |tr| j|jko| j|jko| j|jko| j|j	ko| j
|jko| j|jko| j|jko| j|jko| j|jko| j|jko| j|jko| j|jko| j|jkS tS rS   )rD   r   r   r(   r   r/   r   r7   r   r8   r   r?   r   r0   r   r1   r   r2   r   r9   r    r:   r   r3   r   r>   r   r+   NotImplementedrI   rh   rK   rK   rL   __eq__
  s6    








	




zServerDescription.__eq__c                 C  s
   | |k S rS   rK   rj   rK   rK   rL   __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(   rR   r*   )rI   errmsgrK   rK   rL   __repr__!  s    zServerDescription.__repr__rE   r\   )NNNr%   )N)+rp   
__module____qualname____doc__	__slots__rM   propertyr(   r/   rR   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   rZ   r?   r>   rG   r[   r*   r,   r+   r<   r=   r_   ra   rc   re   rB   rg   rk   rl   rr   r\   __annotations__rK   rK   rK   rL   r       s   
	    /r   )ru   
__future__r   r@   rW   typingr   r   r   Zbsonr   Zbson.objectidr   Zpymongo.hellor   Zpymongo.server_typer	   Zpymongo.typingsr
   r   r   rK   rK   rK   rL   <module>   s   