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m	Z	m
Z
mZmZmZ ddlmZ ddlmZmZmZ ddlmZ ddlmZm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"m#Z# erddlm$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/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 dZ:														dDdEdBdCZ;dS )Fz&Internal network layer helper methods.    )annotationsN)TYPE_CHECKINGAnyMappingMutableMappingOptionalSequenceUnioncast)_decode_all_selective)_csothelpers_sharedmessage)_NO_COMPRESSION)NotPrimaryErrorOperationFailure)_COMMAND_LOGGER_CommandStatusMessage
_debug_log)_OpMsg)_is_speculative_authenticate)receive_messagesendall)CodecOptions)SnappyContextZlibContextZstdContext)_EventListeners)ReadConcern)_ServerMode)ClientSession)MongoClient)
Connection)_Address_CollationIn_DocumentOut_DocumentType)WriteConcernTFconnr"   dbnamestrspecMutableMapping[str, Any]	is_mongosboolread_preferenceOptional[_ServerMode]codec_optionsCodecOptions[_DocumentType]sessionOptional[ClientSession]clientOptional[MongoClient]checkallowable_errors#Optional[Sequence[Union[str, int]]]addressOptional[_Address]	listenersOptional[_EventListeners]max_bson_sizeOptional[int]read_concernOptional[ReadConcern]parse_write_concern_error	collationOptional[_CollationIn]compression_ctx4Union[SnappyContext, ZlibContext, ZstdContext, None]
use_op_msgunacknowledgeduser_fieldsOptional[Mapping[str, Any]]exhaust_allowedwrite_concernOptional[WriteConcern]returnr&   c           )      C  s  t t|}|d }d}|}|r|s|dusJ t||}|r5|r%|js5|jr-|j|d< |r5|||  |dur=||d< |duoC|j}t	j	
 }|rPt||}|rZ| tv rZd}|rm|jrm|jjsm|j||| }}|ru| || t|| |r|rtjnd}||rtjndO }tj||||||d\}}}} |r|dur| |krt||| ntd|dd|d||\}}}|dur||tj krt|||tj  |durttjrttt j!|j"j#|t t||||| j$| j%| j&d | j&d	 | j'd
 |r|dusJ |
dusJ |j(||||
| j%| j'd zOt)| j*j+| |r0|r0d}!dd	i}"n9t,| |}!|!j-| _-|!j.||d}#|#d }"| j/sS|"0d}$|$rS|$| _1|r\|2|"| |rit3j4|"| j5|	|d W nx t6y }% zkt	j	
 | }&t7|%t8t9fr|%j:}'nt;|%}'|durttjrttt j<|j"j#|&|'t t||||| j$| j%| j&d | j&d	 | j't7|%t9d |r|dusJ |
dusJ |j=|&|'|||
| j%| j'|d  d}%~%ww t	j	
 | }&|durttjrttt j>|j"j#|&|"t t||||| j$| j%| j&d | j&d	 | j'd|v d |r<|dus%J |
dus,J |j?|&|"|||
| j%| j'||d	 |rY|jrY|!rY|j@|!A }(tBdtC|(||d }"|"S )a  Execute a command over the socket, or raise socket.error.

    :param conn: a Connection instance
    :param dbname: name of the database on which to run the command
    :param spec: a command document as an ordered dict type, eg SON.
    :param is_mongos: are we connected to a mongos?
    :param read_preference: a read preference
    :param codec_options: a CodecOptions instance
    :param session: optional ClientSession instance.
    :param client: optional MongoClient instance for updating $clusterTime.
    :param check: raise OperationFailure if there are errors
    :param allowable_errors: errors to ignore if `check` is True
    :param address: the (host, port) of `conn`
    :param listeners: An instance of :class:`~pymongo.monitoring.EventListeners`
    :param max_bson_size: The maximum encoded bson size for this server
    :param read_concern: The read concern for this command.
    :param parse_write_concern_error: Whether to parse the ``writeConcernError``
        field in the command response.
    :param collation: The collation for this command.
    :param compression_ctx: optional compression Context.
    :param use_op_msg: True if we should use OP_MSG.
    :param unacknowledged: True if this is an unacknowledged command.
    :param user_fields: Response fields that should be decoded
        using the TypeDecoders from codec_options, passed to
        bson._decode_all_selective.
    :param exhaust_allowed: True if we should enable OP_MSG exhaustAllowed.
    z.$cmdFNreadConcernrC   r   )ctx   )r   clientIdcommandcommandNamedatabaseName	requestIdoperationIddriverConnectionIdserverConnectionId
serverHost
serverPort	serviceId)
service_idok)r1   rI   z$clusterTime)rB   )r   rS   
durationMSfailurerU   rV   rW   rX   rY   rZ   r[   r\   r]   isServerSideError)r^   database_namespeculativeAuthenticate)r   rS   r`   replyrU   rV   rW   rX   rY   rZ   r[   r\   r]   speculative_authenticate)r^   speculative_hellorc   r%   )Dnextiterr   _maybe_add_read_preferencein_transactionleveldocument_update_read_concernenabled_for_commandsdatetimenowr   lowerr   
_encrypter_bypass_auto_encryptionencryptapply_timeoutr   apply_write_concernr   MORE_TO_COMEEXHAUST_ALLOWED_op_msg_raise_document_too_large_query_COMMAND_OVERHEADr   isEnabledForloggingDEBUGr   r   STARTED_topology_settings_topology_ididserver_connection_idr:   r^   publish_command_startr   r(   get_connr   more_to_comeunpack_responsereadyget_cluster_time_process_responser   _check_command_responsemax_wire_version	Exception
isinstancer   r   details_convert_exceptionFAILEDpublish_command_failure	SUCCEEDEDpublish_command_successdecryptraw_command_responser
   r   ))r(   r)   r+   r-   r/   r1   r3   r5   r7   r8   r:   r<   r>   r@   rB   rC   rE   rG   rH   rI   rK   rL   namensrg   origpublishstartflags
request_idmsgsizemax_doc_sizere   response_docunpacked_docscluster_timeexcdurationra   	decrypted r   W/var/www/html/olx_land/venv/lib/python3.10/site-packages/pymongo/synchronous/network.pyrT   =   sX  3




	






'

rT   )TNNNNNFNNFFNFN).r(   r"   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r.   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   r.   rC   rD   rE   rF   rG   r.   rH   r.   rI   rJ   rK   r.   rL   rM   rN   r&   )<__doc__
__future__r   rp   r   typingr   r   r   r   r   r   r	   r
   bsonr   pymongor   r   r   pymongo.compression_supportr   pymongo.errorsr   r   pymongo.loggerr   r   r   pymongo.messager   pymongo.monitoringr   pymongo.network_layerr   r   r   r   r   r   r   pymongo.read_concernr   pymongo.read_preferencesr   "pymongo.synchronous.client_sessionr     pymongo.synchronous.mongo_clientr!   pymongo.synchronous.poolr"   pymongo.typingsr#   r$   r%   r&   pymongo.write_concernr'   _IS_SYNCrT   r   r   r   r   <module>   sP   (