
    nh~.                       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rFd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,m-Z- ddlm.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 dZ:	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ;y)z&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)async_receive_messageasync_sendall)CodecOptions)AsyncClientSession)AsyncMongoClient)AsyncConnection)SnappyContextZlibContextZstdContext)_EventListeners)ReadConcern)_ServerMode)_Address_CollationIn_DocumentOut_DocumentType)WriteConcernFc                b  K   t        t        |            }|dz   }d}|}|r|s|J t        j                  ||      }|r=|r|j                  s/|j
                  r|j                  |d<   |r|j                  ||        |||d<   |duxr |j                  }t        j                  j                         }|rt        ||      }|r|j                         t        v rd}|rI|j                  r=|j                  j                  s'|j                  j!                  |||       d{   x}}|r| j#                  ||       t%        j&                  ||       |rl|rt(        j*                  nd}||rt(        j,                  ndz  }t        j.                  ||||||      \  }}}} |r?|=| |kD  r8t        j0                  |||       n t        j2                  d|dd|d||      \  }}}|>||t        j4                  z   kD  r(t        j0                  |||t        j4                  z          |t7        j8                  t:        j<                        rt?        t6        t@        jB                  |jD                  jF                  |t        t        |            |||| jH                  | jJ                  | jL                  d   | jL                  d	   | jN                  
       |r3|J |
J |jQ                  ||||
| jJ                  | jN                         	 tS        | jT                  jV                  |       d{    |r	|rd}!dd	i}"ntY        | |       d{   }!|!jZ                  | _-        |!j]                  ||      }#|#d   }"| j^                  s|"ja                  d      }$|$r|$| _1        |r|je                  |"|       d{    |r#tg        jh                  |"| jj                  |	|       t        j                  j                         |z
  }&|t7        j8                  t:        j<                        rt?        t6        t@        j|                  |jD                  jF                  |&|"t        t        |            |||| jH                  | jJ                  | jL                  d   | jL                  d	   | jN                  d|v        |r6|J |
J |j                  |&|"|||
| jJ                  | jN                  ||	       |rY|j                  rM|!rK|j                  j                  |!j                                d{   }(t        dt        |(||      d         }"|"S 7  7 7 7 # tl        $ rS}%t        j                  j                         |z
  }&to        |%tp        tr        f      r|%jt                  }'nt        jv                  |%      }'|t7        j8                  t:        j<                        rt?        t6        t@        jx                  |jD                  jF                  |&|'t        t        |            |||| jH                  | jJ                  | jL                  d   | jL                  d	   | jN                  to        |%tr                     |r5|J |
J |j{                  |&|'|||
| jJ                  | jN                  |        d}%~%ww xY w7 w)a  Execute a command over the socket, or raise socket.error.

    :param conn: a AsyncConnection 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 AsyncClientSession instance.
    :param client: optional AsyncMongoClient 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readConcern	collationr   )ctx   )r   clientIdcommandcommandNamedatabaseName	requestIdoperationIddriverConnectionIdserverConnectionId
serverHost
serverPort	serviceId)
service_idok)codec_optionsuser_fieldsz$clusterTime)parse_write_concern_error)r   r/   
durationMSfailurer1   r2   r3   r4   r5   r6   r7   r8   r9   isServerSideError)r:   database_namespeculativeAuthenticate)r   r/   r?   replyr1   r2   r3   r4   r5   r6   r7   r8   r9   speculative_authenticate)r:   speculative_hellorB   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_idaddressr:   publish_command_startr   conn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   ))rg   dbnamespec	is_mongosread_preferencer<   sessionclientcheckallowable_errorsre   	listenersmax_bson_sizeread_concernr>   r+   compression_ctx
use_op_msgunacknowledgedr=   exhaust_allowedwrite_concernnamensrF   origpublishstartflags
request_idmsgsizemax_doc_sizerD   response_docunpacked_docscluster_timeexcdurationr@   	decrypteds)                                            /var/www/html/SchoolMeal/SchoolMeal/pds_admin_SchoolMeal/Backend/venv/lib/python3.12/site-packages/pymongo/asynchronous/network.pyr0   r0   =   sc    f T
D	'	B D***11$HW)?)?"."7"7D((t4%[t#F	(F(FG!!#E8tD4::<?:&##F,=,=,U,U"--55fdMRRRt 64(	dM2'5##1?''A.5oo4-_/
+
C|
 m7L=<X--dD-H 'r1b$m_!

C  TMG<U<U,U%U))$mgF_F_6_`''6-5522?? d,#$&#'77#'#<#<<<?<<?// $$$"""''%% 	( 	
ADII..444.E*.L/jAAE % 2 2D!11+ 2 M )+L::+//?)5D&..|WEEE66 ))$.G	Z   $$&.H''6-7722??#" d,#$&#'77#'#<#<<<?<<?//)Bd)J" $$$"""))%%/  	* 
	
 &## ++33E4N4N4PQQ	1)]KXYZ[
 A Sl 	5 B F  &$$((*U2cO-=>?$'KKG005G++GMM:#188#66CC'# $T$Z 0!'( *'+ww'+'@'@#||A#||A"oo&06F&G" (((&&&--))??$ . 	 	M&V Rs|   DZ/ U !G Z/#U %U&U UA*U /U	0)U EZ/Z, !Z/U U 	U 
Z)EZ$$Z))Z/)TNNNNNFNNFFNFN).rg   r   r{   strr|   zMutableMapping[str, Any]r}   boolr~   zOptional[_ServerMode]r<   zCodecOptions[_DocumentType]r   zOptional[AsyncClientSession]r   zOptional[AsyncMongoClient]r   r   r   z#Optional[Sequence[Union[str, int]]]re   zOptional[_Address]r   zOptional[_EventListeners]r   zOptional[int]r   zOptional[ReadConcern]r>   r   r+   zOptional[_CollationIn]r   z4Union[SnappyContext, ZlibContext, ZstdContext, None]r   r   r   r   r=   zOptional[Mapping[str, Any]]r   r   r   zOptional[WriteConcern]returnr'   )<__doc__
__future__r   rO   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   #pymongo.asynchronous.client_sessionr   !pymongo.asynchronous.mongo_clientr   pymongo.asynchronous.poolr   r   r   r    r!   pymongo.read_concernr"   pymongo.read_preferencesr#   pymongo.typingsr$   r%   r&   r'   pymongo.write_concernr(   _IS_SYNCr0        r   <module>r      s   - "  	 	 	 ' 2 2 7 N M " ;
 !FB9SS204SS2 <@"&+/#'*.&+(,LP /3!,0-m
mm #m 	m
 +m /m *m 'm m :m  m )m !m (m  $m  &!m" J#m$ %m& 'm( -)m* +m, *-m. /mr   