
    h/                     z   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	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mZmZmZ dd	lmZmZ dd
lmZ ddlmZ ddlm Z   ejB                  d      jD                  Z#	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ$ ejB                  d      jD                  Z%efdZ&dZ'd Z(esd Z)yd Z)y)z&Internal network layer helper methods.    N)_decode_all_selective)PY3)helpersmessage)MAX_MESSAGE_SIZE)_NO_COMPRESSION
decompress)AutoReconnectNetworkTimeoutNotPrimaryErrorOperationFailureProtocolError_OperationCancelled)_UNPACK_REPLY_OpMsg)_is_speculative_authenticate)time)_errno_from_exceptionz<iiiic                    t        t        |            }|dz   }|rdnd}d}|}|r|st        j                  ||      }|r=|r|j                  s/|j
                  r|j                  |d<   |r|j                  ||        |||d<   |duxr |j                  }|r*t        j                  j                         }t        ||      }|r|j                         t        v rd}|rD|j                  r8|j                  j                  s"|j                  j!                  ||||      x}}d}|rn|rt"        j$                  nd}||rt"        j&                  ndz  }t        j(                  ||||||||      \  }}} }!|r@|>|!|kD  r9t        j*                  || |       n!t        j,                  ||dd	|d|||	      \  }}} |>| |t        j.                  z   kD  r(t        j*                  || |t        j.                  z          |r_t        j                  j                         z
  }"|j1                  ||||| j2                  
       t        j                  j                         }	 | j4                  j7                  |       |r	|rd}#ddi}$nnt9        | |      }#|#j:                  | _        |#j=                  ||      }%|%d   }$|r|j?                  |$|       |	r#tA        jB                  |$| jD                  |
|       |rFt        j                  j                         z
  "z   }'|jU                  |'|$|||| j2                  |       |rG|j                  r;|#r9|j                  jW                  |#jY                               })t[        |)||      d   }$|$S # tF        $ r}&|r}t        j                  j                         z
  "z   }'tI        |&tJ        tL        f      r|&jN                  }(nt        jP                  |&      }(|jS                  |'|(|||| j2                  
        d}&~&ww xY w)ad  Execute a command over the socket, or raise socket.error.

    :Parameters:
      - `sock`: a raw socket instance
      - `dbname`: name of the database on which to run the command
      - `spec`: a command document as an ordered dict type, eg SON.
      - `secondary_ok`: whether to set the secondaryOkay wire protocol bit
      - `is_mongos`: are we connected to a mongos?
      - `read_preference`: a read preference
      - `codec_options`: a CodecOptions instance
      - `session`: optional ClientSession instance.
      - `client`: optional MongoClient instance for updating $clusterTime.
      - `check`: raise OperationFailure if there are errors
      - `allowable_errors`: errors to ignore if `check` is True
      - `address`: the (host, port) of `sock`
      - `check_keys`: if True, check `spec` for invalid keys
      - `listeners`: An instance of :class:`~pymongo.monitoring.EventListeners`
      - `max_bson_size`: The maximum encoded bson size for this server
      - `read_concern`: The read concern for this command.
      - `parse_write_concern_error`: Whether to parse the ``writeConcernError``
        field in the command response.
      - `collation`: The collation for this command.
      - `compression_ctx`: optional compression Context.
      - `use_op_msg`: True if we should use OP_MSG.
      - `unacknowledged`: True if this is an unacknowledged command.
      - `user_fields` (optional): Response fields that should be decoded
        using the TypeDecoders from codec_options, passed to
        bson._decode_all_selective.
      - `exhaust_allowed`: True if we should enable OP_MSG exhaustAllowed.
    z.$cmd   r   FreadConcernN	collation)ctx)
service_idok   )codec_optionsuser_fields)parse_write_concern_error)r   speculative_hello).nextiterr   _maybe_add_read_preferencein_transactionleveldocument_update_read_concernenabled_for_commandsdatetimenowr   lowerr   
_encrypter_bypass_auto_encryptionencryptr   MORE_TO_COMEEXHAUST_ALLOWED_op_msg_raise_document_too_largequery_COMMAND_OVERHEADpublish_command_startr   socksendallreceive_messagemore_to_comeunpack_response_process_responser   _check_command_responsemax_wire_version	Exception
isinstancer   r   details_convert_exceptionpublish_command_failurepublish_command_successdecryptraw_command_responser   )*	sock_infodbnamespecsecondary_ok	is_mongosread_preferencer   sessionclientcheckallowable_errorsaddress
check_keys	listenersmax_bson_sizeread_concernr    r   compression_ctx
use_op_msgunacknowledgedr   exhaust_allowednamensflagsr!   origpublishstart
request_idmsgsizemax_doc_sizeencoding_durationreplyresponse_docunpacked_docsexcdurationfailure	decrypteds*                                             M/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/pymongo/network.pycommandrm   +   s   n T
D	'	BA1E D11$HW)?)?"."7"7D((y9%[t#F	(F(FG!!%%'8tD4::<?:&##F,=,=,U,U''//j-XXt
'5##1?''A.5oo	/
+
C| m7L=<X--dD-H '2q"dD-_!

C  TMG<U<U,U%U))$mgF_F_6_`$--113e;''&*g):N:N 	( 	
 !!%%'!s#.E !9L#Iz:E%*%7%7I"!11+ 2 M )+L((w?// ..$.G	" %%))+e37HH)) ++/ 	* 	
 &##%%--e.H.H.JK	,Y{STUV7  
 ))--/%7;LLH#1ABC++!44S9--'4WI]I] .  	
s   BM< <	P
B PP
z<iiBc                 .   | j                   j                         }|rt               |z   }nd}t        t	        | d|            \  }}}}|||k7  rt        d|d|      |dk  rt        d|d      ||kD  rt        d|d|d      |d	k(  r5t        t	        | d
|            \  }}}	t        t	        | |dz
  |      |	      }
nt	        | |dz
  |      }
	 t        |   } ||
      S # t        $ r$ t        d|dt        j                               w xY w)z1Receive a raw BSON message or raise socket.error.N   zGot response id z but expected zMessage length (z3) not longer than standard message header size (16)z*) is larger than server max message size ()i  	      zGot opcode )r7   
gettimeoutr   _UNPACK_HEADER_receive_data_on_socketr   _UNPACK_COMPRESSION_HEADERr	   r   KeyErrorkeys)rG   r`   max_message_sizetimeoutdeadlinelength_response_toop_codecompressor_iddataunpack_replys               rl   r9   r9      sC   nn'')G6G#&4	2x8'#FA{G $;Xb cdd|Z`b
 	
   #)+;=
 	
 $$>#Iq(;%
!M 1)Vb[(SUbc&y&2+xHb$W-   b'=K]K]K_`aabs   	C' '-Dg      ?c                    | j                   }|r| j                  }	 t        |d      r|j                         dkD  rd}nL|r&t	        t        |t               z
  t              d      }nt        }| j                  j                  |d|      }|j                  rt        d      |ry|r"t               |kD  rt        j                  d      y)	zABlock until at least one byte is read, or a timeout, or a cancel.Tpendingr   gMbP?)readrz   zhello cancelledNz	timed out)cancel_contextr7   hasattrr   maxminr   _POLL_TIMEOUTsocket_checkerselect	cancelledr   socketrz   )rG   r{   contextr7   readablerz   s         rl   wait_for_readr     s    &&G~~tY'DLLNQ,> !#h&7"GOG+G$33::4dT[:\  )*;<<DFX-nn[11#      c                 x   t        |      }d}|rh	 t        | |       | j                  j                  |      }|dk(  rt        d      ||||t        |      z    |t        |      z  }|t        |      z  }|rht        |      S # t        t
        f$ r'}t        |      t        j                  k(  rY d }~ d }~ww xY w)Nr   r   connection closed)	bytearrayr   r7   recvIOErrorOSErrorr   errnoEINTRr
   lenbytes)rG   r|   r{   bufichunkrh   s          rl   ru   ru   #  s    i2!++F3
 |#$788&+CAE
N#UOAc%j F  Sz W% (-<s   'B B9B43B44B9c                 >   t        |      }t        |      }d}||k  rF	 t        | |       | j                  j	                  ||d        }|dk(  rt        d      ||z  }||k  rF|S # t
        t        f$ r'}t        |      t        j                  k(  rY d }~} d }~ww xY w)Nr   r   )r   
memoryviewr   r7   	recv_intor   r   r   r   r   r
   )rG   r|   r{   r   mv
bytes_readchunk_lengthrh   s           rl   ru   ru   :  s    _
6!i2(~~77:;H
 q #$788,&J 6! 	 W% (-<s   *A& &B5BBB)TNNFNNNFNNFFNF)*__doc__r*   r   r   structbsonr   bson.py3compatr   pymongor   r   pymongo.commonr   pymongo.compression_supportr   r	   pymongo.errorsr
   r   r   r   r   r   pymongo.messager   r   pymongo.monitoringr   pymongo.monotonicr   pymongo.socket_checkerr   Structunpackrt   rm   rv   r9   r   r   ru    r   rl   <module>r      s    -     &  $ + C  2 ; " 8w'.. #/gT +V]]6299  =M $N 2> .r   