3
]ð]¿  ã               @   sH   d Z ddlmZ ddlmZ ddlmZ ddlmZ	 G dd„ de
ƒZdS )	z0Represent one server the driver is connected to.é    )ÚEPOCH_NAIVE)ÚSERVER_TYPE)ÚIsMaster)Útimec               @   sr  e Zd ZdZdSZdTdd„Zedd„ ƒZedd„ ƒZedd „ ƒZ	ed!d"„ ƒZ
ed#d$„ ƒZed%d&„ ƒZed'd(„ ƒZed)d*„ ƒZed+d,„ ƒZed-d.„ ƒZed/d0„ ƒZed1d2„ ƒZed3d4„ ƒZed5d6„ ƒZed7d8„ ƒZed9d:„ ƒZed;d<„ ƒZed=d>„ ƒZed?d@„ ƒZedAdB„ ƒZedCdD„ ƒZedEdF„ ƒZedGdH„ ƒZedIdJ„ ƒZedKdL„ ƒZedMdN„ ƒZ edOdP„ ƒZ!edQdR„ ƒZ"i Z#dS )UÚServerDescriptiona  Immutable representation of one server.

    :Parameters:
      - `address`: A (host, port) pair
      - `ismaster`: Optional IsMaster instance
      - `round_trip_time`: Optional float
      - `error`: Optional, the last error attempting to connect to the server
    Ú_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Ú_meÚ_is_writableÚ_is_readableÚ_ls_timeout_minutesÚ_errorÚ_set_versionÚ_election_idÚ_cluster_timeÚ_last_write_dateÚ_last_update_timeNc             C   sÔ   || _ |sti ƒ}|j| _|j| _|j| _|j| _	|j
| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j | _!|| _"|j#| _$t%ƒ | _&|| _'|j(rÊ|j(t) }|j*ƒ | _+nd | _+d S )N),r   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   Úmer   Ú_timer   r   Úlast_write_dater   Útotal_secondsr   )ÚselfÚaddressZismasterÚround_trip_timeÚerrorÚdelta© r6   ú=/tmp/pip-build-20mum3z4/pymongo/pymongo/server_description.pyÚ__init__)   s6    
zServerDescription.__init__c             C   s   | j S )z(The address (host, port) of this server.)r   )r1   r6   r6   r7   r2   O   s    zServerDescription.addressc             C   s   | j S )zThe type of this server.)r   )r1   r6   r6   r7   r   T   s    zServerDescription.server_typec             C   s   t j| j S )zSThe server type as a human readable string.

        .. versionadded:: 3.4
        )r   Ú_fieldsr   )r1   r6   r6   r7   Úserver_type_nameY   s    z"ServerDescription.server_type_namec             C   s   | j S )z;List of hosts, passives, and arbiters known to this server.)r	   )r1   r6   r6   r7   r   a   s    zServerDescription.all_hostsc             C   s   | j S )N)r
   )r1   r6   r6   r7   r   f   s    zServerDescription.tagsc             C   s   | j S )zReplica set name or None.)r   )r1   r6   r6   r7   r    j   s    z"ServerDescription.replica_set_namec             C   s   | j S )z8This server's opinion about who the primary is, or None.)r   )r1   r6   r6   r7   r!   o   s    zServerDescription.primaryc             C   s   | j S )N)r   )r1   r6   r6   r7   r"   t   s    zServerDescription.max_bson_sizec             C   s   | j S )N)r   )r1   r6   r6   r7   r#   x   s    z"ServerDescription.max_message_sizec             C   s   | j S )N)r   )r1   r6   r6   r7   r$   |   s    z&ServerDescription.max_write_batch_sizec             C   s   | j S )N)r   )r1   r6   r6   r7   r%   €   s    z"ServerDescription.min_wire_versionc             C   s   | j S )N)r   )r1   r6   r6   r7   r&   „   s    z"ServerDescription.max_wire_versionc             C   s   | j S )N)r   )r1   r6   r6   r7   r'   ˆ   s    zServerDescription.set_versionc             C   s   | j S )N)r   )r1   r6   r6   r7   r(   Œ   s    zServerDescription.election_idc             C   s   | j S )N)r   )r1   r6   r6   r7   r)   �   s    zServerDescription.cluster_timec             C   s   | j | jfS )N)r   r   )r1   r6   r6   r7   Úelection_tuple”   s    z ServerDescription.election_tuplec             C   s   | j S )N)r   )r1   r6   r6   r7   r-   ˜   s    zServerDescription.mec             C   s   | j S )N)r   )r1   r6   r6   r7   r,   œ   s    z1ServerDescription.logical_session_timeout_minutesc             C   s   | j S )N)r   )r1   r6   r6   r7   r/       s    z!ServerDescription.last_write_datec             C   s   | j S )N)r   )r1   r6   r6   r7   Ú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   )r1   r6   r6   r7   r3   ¨   s    z!ServerDescription.round_trip_timec             C   s   | j S )z<The last error attempting to connect to the server, or None.)r   )r1   r6   r6   r7   r4   ±   s    zServerDescription.errorc             C   s   | j S )N)r   )r1   r6   r6   r7   r*   ¶   s    zServerDescription.is_writablec             C   s   | j S )N)r   )r1   r6   r6   r7   r+   º   s    zServerDescription.is_readablec             C   s   | j tjkS )N)r   r   ÚMongos)r1   r6   r6   r7   Úmongos¾   s    zServerDescription.mongosc             C   s   | j tjkS )N)r   r   ÚUnknown)r1   r6   r6   r7   Úis_server_type_knownÂ   s    z&ServerDescription.is_server_type_knownc             C   s   | j dk	o| jtjtjfkS )z0Checks if this server supports retryable writes.N)r   r   r   r>   Z	RSPrimary)r1   r6   r6   r7   Úretryable_writes_supportedÆ   s    
z,ServerDescription.retryable_writes_supportedc             C   s
   | j dkS )z0Checks if this server supports retryable writes.é   )r   )r1   r6   r6   r7   Úretryable_reads_supportedÍ   s    z+ServerDescription.retryable_reads_supported)r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )NNN)$Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r8   Úpropertyr2   r   r:   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r;   r-   r,   r/   r<   r3   r4   r*   r+   r?   rA   rB   rD   r=   r6   r6   r6   r7   r      sN          
!	r   N)rH   Zbsonr   Zpymongo.server_typer   Zpymongo.ismasterr   Zpymongo.monotonicr   r.   Úobjectr   r6   r6   r6   r7   Ú<module>   s
   