o
    C©Ì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 )z’Represent 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[dict[str, Any]]]Ú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   úi/var/www/html/Moveonwheels/move_on_wheels/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   