o
    ƒ±h:  ã                   @  s¤   d Z ddlmZ ddlZddlZddlZddlmZ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mZ ddd„ZG dd„ dƒZG dd„ dee ƒZdS )z2Helpers for the 'hello' and legacy hello commands.é    )ÚannotationsN)ÚAnyÚGenericÚMappingÚOptional)ÚObjectId)Úcommon)ÚSERVER_TYPE)ÚClusterTimeÚ_DocumentTypeÚdocúMapping[str, Any]ÚreturnÚintc                 C  s®   |   d¡stjS |   d¡rtjS |   d¡rtjS |   d¡rJ|   d¡r%tjS |   tj¡r.tjS |   tj	¡r7tjS |   d¡r?tj
S |   d¡rGtjS tjS |   d¡d	krTtjS tjS )
z0Determine the server type from a hello response.ÚokÚ	serviceIdÚisreplicasetÚsetNameÚhiddenÚ	secondaryÚarbiterOnlyÚmsgÚisdbgrid)Úgetr	   ÚUnknownÚLoadBalancerÚRSGhostÚRSOtherÚHelloCompatÚPRIMARYÚ	RSPrimaryÚLEGACY_PRIMARYÚRSSecondaryÚ	RSArbiterÚMongosÚ
Standalone)r   © r&   úE/var/www/vip_panel/venv/lib/python3.10/site-packages/pymongo/hello.pyÚ_get_server_type   s*   






r(   c                   @  s    e Zd ZdZdZdZdZdZdS )r   ÚhelloÚismasterÚisWritablePrimaryz
not masterN)Ú__name__Ú
__module__Ú__qualname__ÚCMDÚ
LEGACY_CMDr   r!   ÚLEGACY_ERRORr&   r&   r&   r'   r   9   s    r   c                   @  sš  e Zd ZdZdZdOdPd
d„ZedQdd„ƒZedRdd„ƒZedSdd„ƒZ	edTdd„ƒZ
edUdd„ƒZedVdd„ƒZedRdd„ƒZedRdd „ƒZedRd!d"„ƒZedRd#d$„ƒZedRd%d&„ƒZedWd(d)„ƒZedXd+d,„ƒZedYd.d/„ƒZedWd0d1„ƒZedZd2d3„ƒZedZd4d5„ƒZedUd6d7„ƒZed[d9d:„ƒZed\d<d=„ƒZed]d?d@„ƒZed^dBdC„ƒZed^dDdE„ƒZedZdFdG„ƒZedXdHdI„ƒZedZdJdK„ƒZ edWdLdM„ƒZ!dNS )_ÚHellozHParse a hello response from the server.

    .. versionadded:: 3.12
    )Ú_docÚ_server_typeÚ_is_writableÚ_is_readableÚ
_awaitableFr   r   Ú	awaitableÚboolr   ÚNonec                 C  sJ   t |ƒ| _|| _| jtjtjtjtjfv | _| j	tj
kp| j| _|| _d S ©N)r(   r4   r3   r	   r    r%   r$   r   r5   Úserver_typer"   r6   r7   )Úselfr   r8   r&   r&   r'   Ú__init__I   s   
ü
zHello.__init__c                 C  s   t   | j¡S )zUThe complete hello command response document.

        .. versionadded:: 3.4
        )Úcopyr3   ©r=   r&   r&   r'   ÚdocumentV   s   zHello.documentr   c                 C  ó   | j S r;   )r4   r@   r&   r&   r'   r<   ^   ó   zHello.server_typeúset[tuple[str, int]]c                 C  s8   t ttjt | j dg ¡| j dg ¡| j dg ¡¡ƒƒS )z;List of hosts, passives, and arbiters known to this server.ÚhostsÚpassivesÚarbiters)ÚsetÚmapr   Ú
clean_nodeÚ	itertoolsÚchainr3   r   r@   r&   r&   r'   Ú	all_hostsb   s   ýþÿzHello.all_hostsr   c                 C  s   | j  di ¡S )z&Replica set member tags or empty dict.Útags©r3   r   r@   r&   r&   r'   rN   p   s   z
Hello.tagsúOptional[tuple[str, int]]c                 C  s    | j  d¡rt | j d ¡S dS )z8This server's opinion about who the primary is, or None.ÚprimaryN)r3   r   r   Úpartition_noder@   r&   r&   r'   rQ   u   s   zHello.primaryúOptional[str]c                 C  ó   | j  d¡S )zReplica set name or None.r   rO   r@   r&   r&   r'   Úreplica_set_name}   ó   zHello.replica_set_namec                 C  ó   | j  dtj¡S )NÚmaxBsonObjectSize)r3   r   r   ÚMAX_BSON_SIZEr@   r&   r&   r'   Úmax_bson_size‚   ó   zHello.max_bson_sizec                 C  rW   )NÚmaxMessageSizeBytes)r3   r   r   ÚMAX_MESSAGE_SIZEr@   r&   r&   r'   Úmax_message_size†   r[   zHello.max_message_sizec                 C  rW   )NÚmaxWriteBatchSize)r3   r   r   ÚMAX_WRITE_BATCH_SIZEr@   r&   r&   r'   Úmax_write_batch_sizeŠ   r[   zHello.max_write_batch_sizec                 C  rW   )NÚminWireVersion)r3   r   r   ÚMIN_WIRE_VERSIONr@   r&   r&   r'   Úmin_wire_versionŽ   r[   zHello.min_wire_versionc                 C  rW   )NÚmaxWireVersion)r3   r   r   ÚMAX_WIRE_VERSIONr@   r&   r&   r'   Úmax_wire_version’   r[   zHello.max_wire_versionúOptional[int]c                 C  rT   )NÚ
setVersionrO   r@   r&   r&   r'   Úset_version–   ó   zHello.set_versionúOptional[ObjectId]c                 C  rT   )NÚ
electionIdrO   r@   r&   r&   r'   Úelection_idš   rk   zHello.election_idúOptional[ClusterTime]c                 C  rT   )Nz$clusterTimerO   r@   r&   r&   r'   Úcluster_timež   rk   zHello.cluster_timec                 C  rT   )NÚlogicalSessionTimeoutMinutesrO   r@   r&   r&   r'   Úlogical_session_timeout_minutes¢   rk   z%Hello.logical_session_timeout_minutesc                 C  rB   r;   )r5   r@   r&   r&   r'   Úis_writable¦   rC   zHello.is_writablec                 C  rB   r;   )r6   r@   r&   r&   r'   Úis_readableª   rC   zHello.is_readablec                 C  s   | j  d¡}|rt |¡S d S )NÚme)r3   r   r   rJ   )r=   ru   r&   r&   r'   ru   ®   s   
zHello.meúOptional[datetime.datetime]c                 C  s   | j  di ¡ d¡S )NÚ	lastWriteÚlastWriteDaterO   r@   r&   r&   r'   Úlast_write_dateµ   s   zHello.last_write_dateúOptional[list[str]]c                 C  rT   )NÚcompressionrO   r@   r&   r&   r'   Úcompressors¹   rk   zHello.compressorsú	list[str]c                 C  s   | j  dg ¡S )z³Supported authentication mechanisms for the current user.

        For example::

            >>> hello.sasl_supported_mechs
            ["SCRAM-SHA-1", "SCRAM-SHA-256"]

        ÚsaslSupportedMechsrO   r@   r&   r&   r'   Úsasl_supported_mechs½   s   
zHello.sasl_supported_mechsúOptional[Mapping[str, Any]]c                 C  rT   )z"The speculativeAuthenticate field.ÚspeculativeAuthenticaterO   r@   r&   r&   r'   Úspeculative_authenticateÉ   rV   zHello.speculative_authenticatec                 C  rT   )NÚtopologyVersionrO   r@   r&   r&   r'   Útopology_versionÎ   rk   zHello.topology_versionc                 C  rB   r;   )r7   r@   r&   r&   r'   r8   Ò   rC   zHello.awaitablec                 C  rT   )Nr   rO   r@   r&   r&   r'   Ú
service_idÖ   rk   zHello.service_idc                 C  s   | j  dd¡S )NÚhelloOkFrO   r@   r&   r&   r'   Úhello_okÚ   s   zHello.hello_okc                 C  rT   )NÚconnectionIdrO   r@   r&   r&   r'   Úconnection_idÞ   rk   zHello.connection_idN)F)r   r   r8   r9   r   r:   )r   r   )r   r   )r   rD   )r   r   )r   rP   )r   rS   )r   rh   )r   rl   )r   ro   )r   r9   )r   rv   )r   rz   )r   r}   )r   r€   )"r,   r-   r.   Ú__doc__Ú	__slots__r>   ÚpropertyrA   r<   rM   rN   rQ   rU   rZ   r^   ra   rd   rg   rj   rn   rp   rr   rs   rt   ru   ry   r|   r   r‚   r„   r8   r…   r‡   r‰   r&   r&   r&   r'   r2   A   st    r2   )r   r   r   r   )rŠ   Ú
__future__r   r?   ÚdatetimerK   Útypingr   r   r   r   Úbson.objectidr   Úpymongor   Úpymongo.server_typer	   Úpymongo.typingsr
   r   r(   r   r2   r&   r&   r&   r'   Ú<module>   s   
