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details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 rO   V/var/www/html/olx_land/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   rM   rO   rO   rP   r&   t      zServerDescription.addressintc                 C  rR   )zThe type of this server.)r   rS   rO   rO   rP   r3   y   rT   zServerDescription.server_typestrc                 C  s   t j| j S )zSThe server type as a human readable string.

        .. versionadded:: 3.4
        )r	   _fieldsr   rS   rO   rO   rP   server_type_name~   s   z"ServerDescription.server_type_nameset[tuple[str, int]]c                 C  rR   )z;List of hosts, passives, and arbiters known to this server.)r   rS   rO   rO   rP   r4      rT   zServerDescription.all_hostsMapping[str, Any]c                 C  rR   N)r   rS   rO   rO   rP   r5         zServerDescription.tagsOptional[str]c                 C  rR   )zReplica set name or None.)r   rS   rO   rO   rP   r6      rT   z"ServerDescription.replica_set_nameOptional[tuple[str, int]]c                 C  rR   )z8This server's opinion about who the primary is, or None.)r   rS   rO   rO   rP   r7      rT   zServerDescription.primaryc                 C  rR   r[   )r   rS   rO   rO   rP   r8      r\   zServerDescription.max_bson_sizec                 C  rR   r[   )r   rS   rO   rO   rP   r9      r\   z"ServerDescription.max_message_sizec                 C  rR   r[   )r   rS   rO   rO   rP   r:      r\   z&ServerDescription.max_write_batch_sizec                 C  rR   r[   )r   rS   rO   rO   rP   r;      r\   z"ServerDescription.min_wire_versionc                 C  rR   r[   r   rS   rO   rO   rP   r<      r\   z"ServerDescription.max_wire_versionOptional[int]c                 C  rR   r[   )r   rS   rO   rO   rP   r=      r\   zServerDescription.set_versionOptional[ObjectId]c                 C  rR   r[   )r    rS   rO   rO   rP   r>      r\   zServerDescription.election_idOptional[ClusterTime]c                 C  rR   r[   )r!   rS   rO   rO   rP   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    rS   rO   rO   rP   election_tuple   s   z ServerDescription.election_tuplec                 C  rR   r[   )r   rS   rO   rO   rP   rC      r\   zServerDescription.mec                 C  rR   r[   )r   rS   rO   rO   rP   rB      r\   z1ServerDescription.logical_session_timeout_minutesc                 C  rR   r[   )r"   rS   rO   rO   rP   rK      r\   z!ServerDescription.last_write_datec                 C  rR   r[   )r#   rS   rO   rO   rP   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   rS   rO   rO   rP   r)      s   z!ServerDescription.round_trip_timec                 C  rR   )z-The min latency from the most recent samples.)r   rS   rO   rO   rP   r-      rT   z%ServerDescription.min_round_trip_timec                 C  rR   )z<The last error attempting to connect to the server, or None.)r   rS   rO   rO   rP   r+      rT   zServerDescription.errorboolc                 C  rR   r[   )r   rS   rO   rO   rP   r@      r\   zServerDescription.is_writablec                 C  rR   r[   )r   rS   rO   rO   rP   rA      r\   zServerDescription.is_readablec                 C  s   | j tjkS r[   )r   r	   MongosrS   rO   rO   rP   mongos      zServerDescription.mongosc                 C  s   | j tjkS r[   )r3   r	   UnknownrS   rO   rO   rP   is_server_type_known   ro   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	   rm   	RSPrimaryLoadBalancerrS   rO   rO   rP   retryable_writes_supported   s   
z,ServerDescription.retryable_writes_supportedc                 C  s
   | j dkS )rr      r_   rS   rO   rO   rP   retryable_reads_supported   s   
z+ServerDescription.retryable_reads_supportedOptional[Mapping[str, Any]]c                 C  rR   r[   )r$   rS   rO   rO   rP   rF     r\   z"ServerDescription.topology_versionc                 C  s   t | j|d}| j|_|S )N)r+   )r   r&   rF   r$   )rM   r+   unknownrO   rO   rP   
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 r[   )rH   r   r   r&   r   r3   r   r;   r   r<   r   rC   r   r4   r   r5   r   r6   r   r=   r    r>   r   r7   r   rB   r   r+   NotImplementedrM   r{   rO   rO   rP   __eq__
  s6   









	



zServerDescription.__eq__c                 C  s
   | |k S r[   rO   r}   rO   rO   rP   __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&   rX   r)   )rM   errmsgrO   rO   rP   __repr__!  s   zServerDescription.__repr__rI   rk   )NNNr%   )r&   r   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   )r/   r   )r/   rU   )r/   rV   )r/   rY   )r/   rZ   )r/   r]   )r/   r^   )r/   r`   )r/   ra   )r/   rb   )r/   rc   )r/   r*   )r/   r.   )r/   r,   )r/   rl   )r/   rx   r[   )r+   r,   r/   r   )r{   r   r/   rl   )+r   
__module____qualname____doc__	__slots__rQ   propertyr&   r3   rX   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   ri   rC   rB   rK   rj   r)   r-   r+   r@   rA   rn   rq   ru   rw   rF   rz   r~   r   r   rk   __annotations__rO   rO   rO   rP   r       s   
 	/


r   )r   
__future__r   rD   rf   typingr   r   r   bsonr   bson.objectidr   pymongo.hellor   pymongo.server_typer	   pymongo.typingsr
   r   r   rO   rO   rO   rP   <module>   s   