
    &gC                    0
   % S r SSKJr  SSKrSSKrSSKrSSKJr  SSK	J
r
JrJrJrJrJrJrJrJr  SSKrSSKJrJrJr  SSKJr  SSKJrJrJrJr  SS	KJr  SS
K J!r!   SSK"J#r#  Sr$SSK&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.  SSK/J0r0J1r1  \
(       a  SSK2J3r3J4r4J5r5  SSK6J7r7  SSK8J9r9J:r:J;r;J<r<J=r=  Sr>Sr?Sr@SrASrBSrCSrDSrESrFSrGSrHSrISrJ\AS\BS \CS!0rKS"S#S$S%S&.rL\" S'S(9rMS)\NS*'   SS+ jrO      SS, jrPSS- jrQSS. jrR        SS/ jrSSS0S1S2S3S4.rTS5S6S7S8S9S:S;S<S=S>S>S?S@.rU   S                       SSA jjrV              SSB jrW\R                  " SC5      R                  rZSDr[        SSE jr\\R                  " SF5      R                  r]SSG jr^\R                  " SH5      R                  r_\R                  " SI5      R                  r`\R                  " SJ5      R                  ra            SSK jrb              SSL jrc            SSM jrd\$(       a  \#R                  rd S             SSN jjre                SSO jrf                  SSP jrg                SSQ jrh\$(       a  \#R                  rh S                 SSR jjrj\R                  " SS5      R                  rkSST jrl          SSU jrm        SSV jrn\$(       a  \#R                  rn S         SSW jjrp\ASX\BSY\CSZ0rq " S[ S\5      rr " S] S^\r5      rs " S_ S`\s5      rtSSa jruSbrv                SSc jrw              SSd jrx\$(       a  \#R                  rx              SSe jry              SSf jrz\$(       a  \#R                  rz              SSg jr{ " Sh Si\r5      r|Sjr}            SSk jr~                SSl jr              SSm jr              SSn jr              SSo jr            SSp jr              SSq jr\$(       a  \#GR                  r                SSr jr " Ss St5      r " Su Sv5      r\GR                  \GR                  \GR                  \GR                  0rSw\NSx'    " Sy Sz5      r " S{ S|5      r " S} S~\5      r " S S\5      r " S S\5      rg! \% a    Sr$ GNf = f)zTools for creating `messages
<https://www.mongodb.com/docs/manual/reference/mongodb-wire-protocol/>`_ to be sent to
MongoDB.

.. note:: This module is for internal use and is generally not needed by
   application developers.
    )annotationsN)BytesIO)	TYPE_CHECKINGAnyCallableIterableMappingMutableMappingNoReturnOptionalUnion)CodecOptions_dict_to_bson_make_c_string)Int64)_RAW_ARRAY_BSON_OPTIONSDEFAULT_RAW_BSON_OPTIONSRawBSONDocument_inflate_bson)HelloCompat)_EventListeners)	_cmessageTF)ConfigurationErrorCursorNotFoundDocumentTooLargeExecutionTimeoutInvalidOperationNotPrimaryErrorOperationFailureProtocolError)ReadPreference_ServerMode)SnappyContextZlibContextZstdContext)ReadConcern)_Address_AgnosticClientSession_AgnosticConnection_AgnosticMongoClient_DocumentOutii   i?                   s            s           s       s   documents     s   updates     s   deletes     	documentsupdatesdeletesops)insertupdatedelete	bulkWritereplace)unicode_decode_error_handlerzCodecOptions[Mapping[str, Any]]_UNICODE_REPLACE_CODEC_OPTIONSc                 @    [         R                  " [        [        5      $ )z(Generate a pseudo random 32 bit integer.)randomrandint	MIN_INT32	MAX_INT32 r.   TC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\pymongo/message.py_randintrD   t   s    >>)Y//r.   c                    UR                   nUR                  nU(       a;  U[        R                  R                   :w  d  [	        U5      S:  a  SU ;  a  SU 0n X0S'   U $ )z-Add $readPreference to spec when appropriate.r,   $query$readPreference)modedocumentr!   SECONDARY_PREFERREDlen)specread_preferencerH   rI   s       rC   _maybe_add_read_preferencerN   y   s^     D''H ;;@@@CMTUDU4d#D"*Kr.   c                F    [        U 5      U R                  R                  S.$ )z<Convert an Exception into a failure document for publishing.)errmsgerrtype)str	__class____name__	exceptions    rC   _convert_exceptionrW      s    )n1D1D1M1MNNr.   c                \    [        U 5      U R                  U R                  R                  S.$ )zeConvert an Exception into a failure document for publishing,
for use in client-level bulk write API.
)rP   coderQ   )rR   rY   rS   rT   rU   s    rC   _convert_client_bulk_exceptionrZ      s+    
 i.&&// r.   c                ,   UR                  SS5      nSUS.nUR                  SUR                  SS5      5      nU(       aN  UR                  S5      (       a  US	SS
0S.US'   O,SUR                  SS5      US.nSU;   a  US   US'   U/US'   U$ U S:X  a  [        US   5      US'   U$ U S:X  af  SU;   a  SUS   S./US'   U$ UR                  S5      SL a>  US:X  a8  US   S   nUS   R                  SUS   R                  S5      5      nSUS./US'   U$ )z6Convert a legacy write result to write command format.nr   r,   )okr\   rP   err wtimeout@   T)rP   rY   errInfowriteConcernErrorrY      )indexrY   rP   rb   writeErrorsr6   r2   r7   upserted)re   _idupdatedExistingFr3   urh   q)getrK   )		operationcommandresultaffectedresrP   errorr7   rh   s	            rC   _convert_write_resultrs      sX   
 zz#q!H
"CZZ&**UB"78F::j!!28"R\^bQc'dC#$  FA)>&QEF"#))#4i "'CJHw{+,C J 
h	)*6*3EFGC
O J ZZ)*e3A Y'*F+//%)?@C)*378C
OJr.   rd             )tailableoplogReplaynoCursorTimeout	awaitDataallowPartialResultsfiltersorthintcommentmaxScan	maxTimeMSmaxmin	returnKeyshowRecordIdsnapshot)rF   z$orderbyz$hintz$commentz$maxScanz
$maxTimeMSz$maxz$minz
$returnKeyz$showRecordIdz$showDiskLocz	$snapshotc                   SU 0nSU;   ay  UR                  UR                  5        VVs/ s H  u  pU[        ;   a  [        U   U4OX4PM     snn5        SU;   a  UR                  S5        SU;   a  UR                  S5        OXS'   U(       a  X+S'   U(       a  X;S'   U(       a  [	        U5      US'   US	:  a  S
US'   U(       a  XE:X  a  US-  nX[S'   UR
                  (       a'  U	(       a  U	R                  (       d  UR                  US'   U(       a  XS'   U
b  XS'   U(       aE  UR                  [        R                  5        VVs/ s H  u  pXm-  (       d  M  US
4PM     snn5        U$ s  snnf s  snnf )z!Generate a find command document.findrF   $explainrG   r|   
projectionskiplimitr   TsingleBatchr,   	batchSizereadConcern	collationallowDiskUse)	r7   items
_MODIFIERSpopabslevelin_transactionrI   _OPTIONS)collrL   r   r   r   
batch_sizeoptionsread_concernr   sessionallow_disk_usecmdkeyvalopts                  rC   _gen_find_commandr      sc    "4.C4

 !%

 ,HC +.*;C#&#K ,	
 GGJ#GG%&H&LF5zG19!%C !OJ%K7w/E/E)22M$K!,N

0@R0@HCGMKS$K0@RSJGB Ss   $E+
E1
E1
c                `    XS.nU(       a  X&S'   Ub  X6S'   Ub  UR                   S:  a  XFS'   U$ )z$Generate a getMore command document.)getMore
collectionr   r   	   r   )max_wire_version)	cursor_idr   r   max_await_time_msr   connr   s          rC   _gen_get_more_commandr     sD     '0DC%K$,Kt449 IJr.   z<iiiiiiB   c           
         UR                  U5      n[        5       n[        [        [	        U5      -   USSU [	        U5      UR
                  5      nXEU-   4$ )zDTakes message data, compresses it, and adds an OP_COMPRESSED header.r   i  )compressrD   _pack_compression_header_COMPRESSION_HEADER_SIZErK   compressor_id)rm   datactx
compressed
request_idheaders         rC   	_compressr   &  s[     d#JJ% 3z?2	D	F 
***r.   z<iiiic                V    [        5       n[        S[        U5      -   USU 5      nX#U-   4$ )zlTakes message data and adds a message header based on the operation.

Returns the resultant message string.
rt   r   )rD   _pack_headerrK   )rm   r   ridmessages       rC   __pack_messager   <  s0    
 *C2D	>39=G$r.   z<iz<IBz<Bc                   [        USU5      n[        U S5      n[        U5      nSnU(       a  Ub}  [        S5      n	[	        U5      n
U Vs/ s H  n[        USU5      PM     nn[        U
5      [        S U 5       5      -   S-   n[        U5      nX}-  n[        S U 5       5      nXeXU
/UQnOXe/nSR                  U5      Xx4$ s  snf )zGet a OP_MSG message.

Note: this method handles multiple documents in a type one payload but
it does not perform batch splitting and the total message size is
only checked *after* generating the entire message.
Fr   r,   c              3  8   #    U  H  n[        U5      v   M     g 7fNrK   .0docs     rC   	<genexpr>$_op_msg_no_header.<locals>.<genexpr>a  s     !Cls#c((l      c              3  8   #    U  H  n[        U5      v   M     g 7fr   r   r   s     rC   r   r   d  s     <|3s88|r   r.   )	r   _pack_op_msg_flags_typerK   
_pack_byter   sum	_pack_intr   join)flagsrn   
identifierdocsoptsencoded
flags_type
total_sizemax_doc_sizetype_onecstringr   encoded_docssizeencoded_sizer   s                   rC   _op_msg_no_headerr   K  s     GUD1G(2JWJLd&a= ,CGH4Cc5$74H7|c!Cl!CCCaG 
<|<<XWT|T$88D>:33 Is   Cc                F    [        XX#U5      u  pgn[        SXe5      u  pXXx4$ )zInternal OP_MSG message helper.  )r   r   )
r   rn   r   r   r   r   msgr   max_bson_sizer   s
             rC   _op_msg_compressedr   k  s1     &7uzY]%^"C]s(HCZ..r.   c                F    [        XX#U5      u  pVn[        SU5      u  pXXg4$ )z*Internal compressed OP_MSG message helper.r   )r   r   )
r   rn   r   r   r   r   r   r   r   
op_messages
             rC   _op_msg_uncompressedr   y  s2     '8
Z^&_#Dm+D$7J:<<r.   c                x   X!S'   Ub&  SU;  a   UR                   (       a  UR                  US'   [        [        U5      5      n [        U   nUR                  U5      n U(       a  [        XXxXE5      U(       a  XU'   $ $ [        XXxU5      U(       a  XU'   $ $ ! [         a    SnSn NJf = f! U(       a  XU'   f f = f)zGet a OP_MSG message.$dbNrG   r_   )	rH   rI   nextiter
_FIELD_MAPr   KeyErrorr   r   )	r   rn   dbnamerM   r   r   namer   r   s	            rC   _op_msgr     s     EN"'8'G)8)A)AG%&WD%
{{:&'%ejR "&J  $EJdK "&J   
 "&J s$   B B+ >B+ B('B(+B9c                   [        USU5      nU(       a  [        USU5      nOSn[        [        U5      [        U5      5      n	SR                  [	        U 5      [
        R                  " U5      [	        U5      [	        U5      UU/5      U	4$ )zGet an OP_QUERY message.Fr.   )r   r   rK   r   r   bsonr   )
r   collection_namenum_to_skipnum_to_returnqueryfield_selectorr   r   efsr   s
             rC   _query_implr     s     E5$/GNE48Gc#h/M'"##O4+&-(		
 	 r.   c           	     F    [        XX#XEU5      u  p[        SX5      u  pXU	4$ )z)Internal compressed query message helper.  )r   r   )r   r   r   r   r   r   r   r   op_queryr   r   r   s               rC   _query_compressedr     s6     *+eUYH x-HC]""r.   c           	     F    [        XX#XEU5      u  px[        SU5      u  pXU4$ )zInternal query message helper.r   )r   r   )r   r   r   r   r   r   r   r   r   r   r   s              rC   _query_uncompressedr     s6     *+eUYH dH-HC]""r.   c           
     H    U(       a  [        XX#XEXg5      $ [        XX#XEU5      $ )zGet a **query** message.)r   r   )r   r   r   r   r   r   r   r   s           rC   _queryr     s7      k%Y]
 	
 +eUY r.   z<qc                    SR                  [        [        R                  " U 5      [	        U5      [        U5      /5      $ )zGet an OP_GET_MORE message.r.   )r   _ZERO_32r   r   r   _pack_long_longr   r   r   s      rC   _get_more_implr    s9    880m$I&		
 r.   c                0    [        S[        XU5      U5      $ )z+Internal compressed getMore message helper.  )r   r  r   r   r   r   s       rC   _get_more_compressedr    s     T>/)TVYZZr.   c                .    [        S[        XU5      5      $ )z Internal getMore message helper.r  )r   r  r  s      rC   _get_more_uncompressedr	    s     $y YZZr.   c                @    U(       a  [        XX#5      $ [        XU5      $ )zGet a **getMore** message.)r  r	  r  s       rC   	_get_morer  (  s!     #OISS!/)LLr.   s
   documents s   updates s   deletes c                      \ rS rSrSrSr                SS jr\SS j5       r\SS j5       r	\SS j5       r
\SS j5       rSS	 jrSS
 jrSrg)_BulkWriteContextBasei>  z]Private base class for wrapping around AsyncConnection to use with write splitting functions.)db_namer   op_idr   fieldpublish
start_time	listenersr   r   op_typecodecc	                0   Xl         X0l        X@l        XPl        UR                  U l        X l        [        U R                     U l        [        R                  R                  5       U l        X`l        [        UR                  5      U l        Xpl        Xl        g r   )r  r   r  r  enabled_for_commandsr  r   r   r  datetimenowr  r   boolcompression_contextr   r  r  )	selfdatabase_namecmd_namer   operation_idr  r   r  r  s	            rC   __init___BulkWriteContextBase.__init__P  sq     %	!
" 55			*
"++//1T556
r.   c                .    U R                   R                  $ )z#A proxy for SockInfo.max_bson_size.)r   r   r  s    rC   r   #_BulkWriteContextBase.max_bson_sizeh  s     yy&&&r.   c                    U R                   (       a  U R                  R                  S-
  $ U R                  R                  $ )z&A proxy for SockInfo.max_message_size.rt   )r   r   max_message_sizer#  s    rC   r&  &_BulkWriteContextBase.max_message_sizem  s0     ==99--22yy)))r.   c                .    U R                   R                  $ )z*A proxy for SockInfo.max_write_batch_size.)r   max_write_batch_sizer#  s    rC   r)  *_BulkWriteContextBase.max_write_batch_sizeu  s     yy---r.   c                    U R                   $ )z:The maximum size of a BSON command before batch splitting.)r   r#  s    rC   max_split_size$_BulkWriteContextBase.max_split_sizez  s     !!!r.   c                    U R                   R                  UUU R                  UU R                  R                  U R                  R
                  U R                  U R                  R                  U R                  S9	  g)z Publish a CommandSucceededEvent.r  N)	r  publish_command_successr   r   addressserver_connection_idr  
service_idr  )r  r   replydurations       rC   _succeed_BulkWriteContextBase._succeed  s^    ..IIIIII**JJII  ,, 	/ 
	
r.   c                    U R                   R                  UUU R                  UU R                  R                  U R                  R
                  U R                  U R                  R                  U R                  S9	  g)zPublish a CommandFailedEvent.r/  N)	r  publish_command_failurer   r   r1  r2  r  r3  r  )r  r   failurer5  s       rC   _fail_BulkWriteContextBase._fail  s^    ..IIIIII**JJII  ,, 	/ 
	
r.   )r  r   r   r  r  r  r   r  r  r  r   r  Nr  rR   r  rR   r   r)   r  intr  r   r    Optional[_AgnosticClientSession]r  r>  r  r   returnr>  )r   r>  r4  r+   r5  datetime.timedeltarA  None)r   r>  r:  r+   r5  rB  rA  rC  )rT   
__module____qualname____firstlineno____doc__	__slots__r   propertyr   r&  r)  r,  r6  r;  __static_attributes__rB   r.   rC   r  r  >  s    gI  "	
  # 2  0 ' ' * * . . " "

r.   r  c                     ^  \ rS rSrSrSr                SU 4S jjr      SS jr        S	S jrSr	U =r
$ )
_BulkWriteContexti  z]A wrapper around AsyncConnection/Connection for use with the collection-level bulk write API.rB   c	           
     2   > [         T	U ]  UUUUUUUU5        g r   superr   )
r  r  r  r   r  r  r   r  r  rS   s
            rC   r   _BulkWriteContext.__init__  s*     			
r.   c                    U R                   S-   n[        X0R                  XU R                  U 5      u  pEnU(       d  [	        S5      eXEU4$ )N.$cmdcannot do an empty bulk write)r  _do_batched_op_msgr  r  r   )r  r   r   	namespacer   r   to_sends          rC   batch_command_BulkWriteContext.batch_command  sN     LL7*	#5||S

D$
 
 "#BCC''r.   c           	        X1U R                   '   U R                  R                  UU R                  UU R                  R
                  U R                  R                  U R                  U R                  R                  5        U$ )Publish a CommandStartedEvent.)	r  r  publish_command_startr  r   r1  r2  r  r3  )r  r   r   r   s       rC   _start_BulkWriteContext._start  sc     DJJ,,LLIIII**JJII  	
 
r.   r=  )r   MutableMapping[str, Any]r   list[Mapping[str, Any]]rA  zAtuple[int, Union[bytes, dict[str, Any]], list[Mapping[str, Any]]])r   r^  r   r>  r   r_  rA  r^  rT   rD  rE  rF  rG  rH  r   rW  r\  rJ  __classcell__rS   s   @rC   rL  rL    s    gI

 
 "	

 
 #
 2
 
 
,	(+	(3J	(	J	(+9<D[	! r.   rL  c                  B    \ rS rSrSr      SS jr\SS j5       rSrg)_EncryptedBulkWriteContexti  rB   c                    U R                   S-   n[        X0R                  XU R                  U 5      u  pEU(       d  [	        S5      eUR                  SS5      S-   n[        [        U5      US  [        5      nSXu4$ )NrR  rS  r0   r   r   )	r  _encode_batched_write_commandr  r  r   re   r   
memoryviewr   )r  r   r   rU  r   rV  	cmd_startoutgoings           rC   rW  (_EncryptedBulkWriteContext.batch_command  sz     LL7*	4||S

D
 "#BCC IIgq)A-	 C!<>VW8$$r.   c                    [         $ )z Reduce the batch splitting size.)_MAX_SPLIT_SIZE_ENCr#  s    rC   r,  )_EncryptedBulkWriteContext.max_split_size  s
     #"r.   N)r   r^  r   r_  rA  z3tuple[int, dict[str, Any], list[Mapping[str, Any]]]r@  )	rT   rD  rE  rF  rH  rW  rI  r,  rJ  rB   r.   rC   rd  rd    s8    I%+%3J%	<% # #r.   rd  c                J    U S:X  a  [        SX4-  5      e[        U < S35      e)z-Internal helper for raising DocumentTooLarge.r6   zfBSON document too large (%d bytes) - the connected server supports BSON document sizes up to %d bytes.z command document too large)r   )rm   doc_sizemax_sizes      rC   _raise_document_too_largerr    s>    H ",-
 	
 ).IJKKr.   i    c                   UR                   nUR                  nUR                  n	U(       a  SOSn
UR                  U
5        UR                  S5        UR                  [	        USU5      5        UR                  S5        UR                  5       nUR                  S5         UR                  [        U    5        / nSnU H  n[	        USU5      n[        U5      nUR                  5       U-   nUS:H  =(       a    UU	:  nU(       + =(       a    UU:  nU(       d  U(       a6  [        [        R                  5       5      U    n[        U[        U5      U5        UU	:  a    O2UR                  U5        UR                  U5        US	-  nX:X  d  M    O   UR                  5       nUR                  U5        UR                  [!        UU-
  5      5        UU4$ ! [         a    [        S5      Sef = f)
zCreate a batched OP_MSG write.r1         r0   F   Unknown commandNr   r,   )r   r)  r&  writer   tell_OP_MSG_MAPr   r   rK   listr   keysrr  appendseekr   )rm   rn   r   ackr   r   bufr   r)  r&  r   size_locationrV  idxr   value
doc_lengthnew_message_sizedoc_too_largeunacked_doc_too_largewrite_oplengths                         rC   _batched_op_msg_implr    s    %%M33++#&,?EIIe IIgIImGUD12 IIgHHJMII!"<		+i() G
Cc5$/Z
88:
2qJ&69I&I %( HZ--G1JOO-.y9H%hE
MJ..		%sq&1 6 XXZFHH]IIi./0F?I  <01t;<s   !G G(c           	     Z    [        5       n[        XX#XEU5      u  pxUR                  5       U4$ )zGEncode the next batched insert, update, or delete operation
as OP_MSG.
)_BytesIOr  getvalue)	rm   rn   r   r~  r   r   r  rV  _s	            rC   _encode_batched_op_msgr  E  s/     *C%i$TPSTJG<<>7""r.   c                    [        XX#XE5      u  pgUR                  R                  c   e[        SXeR                  R                  5      u  pXU4$ )zUCreate the next batched insert, update, or delete operation
with OP_MSG, compressed.
r   )r  r   r  r   )
rm   rn   r   r~  r   r   r   rV  r   r   s
             rC   _batched_op_msg_compressedr  Z  sM     +9t$TMD88''333dHH,H,HIOJG##r.   c           	     f   [        5       nUR                  [        5        UR                  S5        [        XX#XEU5      u  pxUR	                  S5        [        5       n	UR                  [        U	5      5        UR	                  S5        UR                  [        U5      5        XR                  5       U4$ )z"OP_MSG implementation entry point.         r   r   )r  rw  _ZERO_64r  r}  rD   r   r  )
rm   rn   r   r~  r   r   r  rV  r  r   s
             rC   _batched_op_msgr  l  s     *C IIhII12*9t$UXYOG HHQKJIIi
#$HHQKIIi ||~w..r.   c                    U R                  SS5      S   US'   SU;   a  [        US   R                  SS5      5      nOSnUR                  R                  (       a  [        XX6XE5      $ [        XX6XE5      $ )zJCreate the next batched insert, update, or delete operation
using OP_MSG.
.r,   r   r   writeConcernwT)splitr  rl   r   r  r  r  )rU  rm   rn   r   r   r   r~  s          rC   rT  rT    sq     __S!,Q/GEN 7>*..sA67
xx##))dSS9t$DDr.   c                     ^  \ rS rSrSrSr              SU 4S jjr        SS jr          S	S jrSr	U =r
$ )
_ClientBulkWriteContexti  zYA wrapper around AsyncConnection/Connection for use with the client-level bulk write API.rB   c           
     2   > [         TU ]  UUUUUUSU5        g )Nr   rN  )	r  r  r  r   r  r  r   r  rS   s	           rC   r    _ClientBulkWriteContext.__init__  s*     			
r.   c                b    [        XX0R                  U 5      u  pEpgU(       d  [        S5      eXEXg4$ )NrS  )_client_do_batched_op_msgr  r   )r  r   
operations
namespacesr   r   to_send_ops
to_send_nss           rC   rW  %_ClientBulkWriteContext.batch_command  s;     4MZT4
0
 "#BCC77r.   c           	         X1S'   XAS'   U R                   R                  UU R                  UU R                  R                  U R                  R
                  U R                  U R                  R                  5        U$ )rZ  r5   nsInfo)r  r[  r  r   r1  r2  r  r3  )r  r   r   op_docsns_docss        rC   r\  _ClientBulkWriteContext._start  sf     E
H,,LLIIII**JJII  	
 
r.   )r  rR   r  rR   r   r)   r  r>  r  r   r   r?  r  r   )r   r^  r  #list[tuple[str, Mapping[str, Any]]]r  	list[str]rA  zZtuple[int, Union[bytes, dict[str, Any]], list[Mapping[str, Any]], list[Mapping[str, Any]]])
r   r^  r   r>  r  r_  r  r_  rA  r^  r`  rb  s   @rC   r  r    s    cI

 
 "	

 
 #
 2
 
*8%8 88 	8
 
d8%  )	
 ) 
" r.   r  i  c                ,   U(       a  SOSnUR                  U5        UR                  S5        UR                  U 5        UR                  S5        UR                  5       nUR                  S5        UR                  S5        U H  nUR                  U5        M     UR                  5       nUR                  5       n	UR                  U5        UR                  [        X-
  5      5        UR                  U5        UR                  S5        UR                  5       nUR                  S5        UR                  S5        U H  n
UR                  U
5        M     UR                  5       n	UR                  U5        UR                  [        X-
  5      5        U	$ )Nr1   rt  r0   ru  s   ops s   nsInfo )rw  rx  r}  r   )command_encodedto_send_ops_encodedto_send_ns_encodedr~  r  r   r  
op_encodedresume_locationr  
ns_encodeds              rC   _client_construct_op_msgr    s9    $',?EIIe IIgIIo IIgHHJMII!"IIj)
		* *hhjOXXZFHH]IIi./0HH_ IIgHHJMII!"IIm(
		* ) XXZFHH]IIi./0Mr.   c                r           SS jnUR                   nUR                  n	UR                  n
[        U SU5      nU(       d  U" S[	        U5      U[
        -   5        / SQnU R                  S5      (       a  UR                  S5        U R                  S5      (       a  UR                  S5        U R                  S5      (       a  UR                  S5        U Vs0 s H  oX   _M	     nn[	        [        USU5      5      nU
[        U-   -
  n0 n/ n/ n/ n/ nSnSnSn[        X5       GHr  u  u  nnnUnUS	:X  a*  U(       d#  [	        [        US
   SU5      5      nU" UUU5        US:X  a,  SnU(       d#  [	        [        US   SU5      5      nU" UUU5        SnSnUU;  a  SU0n[	        U5      n U UU'   UU   UU'   [        USU5      n![	        U!5      n"U(       a  [        USU5      n#[	        U#5      nU(       d  U" UU"U[
        -   5        UU-   U"-   U-   n$U$U:  a  US:X  a  [        UU"U[
        -   5          OgUR                  U5        UR                  U!5        UU"-  nU(       a'  UR                  U5        UR                  W#5        UU-  nUS-  nUU	:X  d  GMs    O   [        UUUX65      n%UUU%4$ s  snf )z:Create a batched OP_MSG write for client-level bulk write.c                (    X:  a  [        XU5        g g r   )rr  )r  rp  r   s      rC   _check_doc_size_limits;_client_batched_op_msg_impl.<locals>._check_doc_size_limits  s    
 %g? r.   Fr9   )r9   
errorsOnlyorderedbypassDocumentValidationr   letr   r6   rI   r:   r7   
updateModsNnsr,   )r  rR   rp  r>  r   r>  rA  rC  )r   r)  r&  r   rK   _COMMAND_OVERHEADrl   r|  _OP_MSG_OVERHEADziprr  r  )&rn   r  r  r~  r   r   r  r  r   r)  r&  r  abridged_keysr   command_abridgedcommand_len_abridgedmax_doc_sequences_bytesns_infor  r  r  r  total_ops_lengthtotal_ns_lengthr  real_op_typeop_docrU  r  rp  ns_doc	ns_lengthnew_ns_indexop_doc_encoded	op_lengthns_doc_encodedr  r  s&                                         rC   _client_batched_op_msg_implr    s,   @@@ @ 
	@ %%M33++#GUD9O {C,@-RcBcd ;M{{-..78{{9Y'{{5U#5BC]cW\)]C}-=udKL /2BEY2YZG+-K*,J')&(O
C-0-H)v	8#}VJ-?MN&|X}M9$G}VL-A5$OP&|X}M	G#I&Fz?L!-GI "),w 'vud;'	*65$?NN+I "7I}GX7XY+o=	IIU55ax)'9mN_>_` 	6""">2I%f%%%n5y(Oq &&q .Iv &,.@#F 
F**] Ds   J4c           	     \    [        5       n[        XX#XEU5      u  pxn	UR                  5       Xx4$ )zDEncode the next batched client-level bulkWrite
operation as OP_MSG.
)r  r  r  )
rn   r  r  r~  r   r   r  r  r  r  s
             rC   _client_encode_batched_op_msgr    s6     *C!<Zd"KQ <<>;22r.   c                    [        XX#XE5      u  pgnUR                  R                  c   e[        SXeR                  R                  5      u  pXXx4$ )zRCreate the next batched client-level bulkWrite operation
with OP_MSG, compressed.
r   )r  r   r  r   )rn   r  r  r~  r   r   r   r  r  r   r   s              rC   !_client_batched_op_msg_compressedr    sV     %BZd%!Dz 88''333dHH,H,HIOJK33r.   c           	     h   [        5       nUR                  [        5        UR                  S5        [        XX#XEU5      u  pxn	UR	                  S5        [        5       n
UR                  [        U
5      5        UR	                  S5        UR                  [        U	5      5        XR                  5       Xx4$ )z=OP_MSG implementation entry point for client-level bulkWrite.r  r   r   )r  rw  r  r  r}  rD   r   r  )rn   r  r  r~  r   r   r  r  r  r  r   s              rC   _client_batched_op_msgr    s     *C IIhII12&AZd'#KV
 HHQKJIIi
#$HHQKIIi ||~{>>r.   c                    SU S'   SU ;   a  [        U S   R                  SS5      5      nOSnUR                  R                  (       a  [	        XX%X45      $ [        XX%X45      $ )zGCreate the next batched client-level bulkWrite
operation using OP_MSG.
adminr   r  r  r,   T)r  rl   r   r  r  r  )rn   r  r  r   r   r~  s         rC   r  r    sb     GEN 7>*..sA67
xx##0jW[aa!'zRRr.   c           	     Z    [        5       n[        XX#XEU5      u  pxUR                  5       U4$ )z:Encode the next batched insert, update, or delete command.)r  _batched_write_command_implr  )	rU  rm   rn   r   r   r   r  rV  r  s	            rC   rg  rg    s0     *C,Y7RV]`aJG<<>7""r.   c                   UR                   nUR                  nU[        -   n	UR                  n
UR	                  [
        5        UR	                  U R                  S5      5        UR	                  [        5        UR	                  [        5        UR                  5       nUR	                  [        R                  " U5      5        UR                  SS5        UR                  5          UR	                  [        U   5        UR                  5       S-
  n/ nSnU GH#  n[!        U5      R                  S5      n[#        USU5      n[%        U5      U	:  nU(       a6  ['        [(        R+                  5       5      U   n[-        U[%        U5      U5        US	:  =(       a+    UR                  5       [%        U5      -   [%        U5      -   U
:  nX:  nU(       d  U(       a    OgUR	                  [.        5        UR	                  U5        UR	                  [        5        UR	                  U5        UR1                  U5        US	-  nGM&     UR	                  [2        5        UR                  5       nUR                  U5        UR	                  [5        UU-
  S	-
  5      5        UR                  U5        UR	                  [5        UU-
  5      5        UU4$ ! [         a    [        S5      Sef = f)
z(Create a batched OP_QUERY write command.utf8rf  r-   rv  Nr   r   Fr,   )r   r)  r  r,  rw  r   encode_ZERO_8_SKIPLIMrx  r   r}  truncate_OP_MAPr   r   rR   r   rK   rz  r   r{  rr  _BSONOBJr|  _ZERO_16r   )rU  rm   rn   r   r   r   r  r   r)  max_cmd_sizer,  command_start
list_startrV  r  r   r   r  r  r  enough_dataenough_documentsr  s                          rC   r  r    sM    %%M33 !#44L''N IIhIIiv&'IIgIIh HHJMIIdkk'"# HHROLLN<		')$%
 aJG
C#hoof%c5$/ E
\1JOO-.y9H%hE
MJQhYCHHJS$9CJ$F>#Y6*		(		#		'		%sq' . IIh XXZFHHZIIi+a/01HH]IIi./0F?O  <01t;<s   %K Kc                      \ rS rSrSrSr\R                  " S5      R                  r	Sr
SS jr S     SS jjrS\SS	4         SS
 jjrSS jrSS jr\SS j5       r\SS j5       rSrg)_OpReplyiC  z$A MongoDB OP_REPLY response message.)r   r   number_returnedr2   z<iqiir,   c                H    Xl         [        U5      U l        X0l        X@l        g r   )r   r   r   r  r2   )r  r   r   r  r2   s        rC   r   _OpReply.__init__K  s    
y)."r.   Nc                   U R                   S-  (       a'  Uc  [        S5      eSU4-  nSUSS.n[        USU5      eU R                   S-  (       a  [        R                  " U R
                  5      R                  5       nUR                  SS5        US	   R                  [        R                  5      (       a  [        US	   U5      eUR                  S
5      S:X  a.  Sn[        UR                  S	U5      UR                  S
5      U5      e[        SUR                  S	5      -  UR                  S
5      U5      eU R
                  (       a  U R
                  /$ / $ )ad  Check the response header from the database, without decoding BSON.

Check the response for errors and unpack.

Can raise CursorNotFound, NotPrimaryError, ExecutionTimeout, or
OperationFailure.

:param cursor_id: cursor_id we sent to get this response -
    used for raising an informative exception when we get cursor id not
    valid at server response.
r,   z"No cursor id for getMore operationzCursor not found, cursor id: %dr   +   )r]   rP   rY   r-   r]   z$errrY   2   zoperation exceeded time limitzdatabase error: %s)r   r    r   r   BSONr2   decode
setdefault
startswithr   LEGACY_ERRORr   rl   r   r   )r  r   user_fieldsr   errobjerror_objectdefault_msgs          rC   raw_response_OpReply.raw_responseQ  sA    ::> #$HII 4ylBCb9F b&11ZZ!^!%4>>!:!A!A!CL##D!,F#..{/G/GHH%l6&:LII!!&)R/=& $$V[9<;K;KF;SUa  #$|'7'7'??  ( 
 >>NN##	r.   Fc                    U R                  U5        U(       a!  [        R                  " U R                  U5      $ [        R                  " U R                  X#5      $ )a  Unpack a response from the database and decode the BSON document(s).

Check the response for errors and unpack, returning a dictionary
containing the response data.

Can raise CursorNotFound, NotPrimaryError, ExecutionTimeout, or
OperationFailure.

:param cursor_id: cursor_id we sent to get this response -
    used for raising an informative exception when we get cursor id not
    valid at server response
:param codec_options: an instance of
    :class:`~bson.codec_options.CodecOptions`
:param user_fields: Response fields that should be decoded
    using the TypeDecoders from codec_options, passed to
    bson._decode_all_selective.
)r  r   
decode_allr2   _decode_all_selectiver  r   codec_optionsr  legacy_responses        rC   unpack_response_OpReply.unpack_response}  sA    0 	)$??4>>=AA))$..-UUr.   c                N    U R                  US9nU R                  S:X  d   eUS   $ )Unpack a command response.r   r,   r   )r  r  )r  r   r   s      rC   command_response_OpReply.command_response  s2    ##-#@##q(((Awr.   c                    [         ez)Return the bytes of the command response.)NotImplementedErrorr#  s    rC   raw_command_response_OpReply.raw_command_response  s
     "!r.   c                    g)+Is the moreToCome bit set on this response?FrB   r#  s    rC   more_to_come_OpReply.more_to_come  s     r.   c                F    U R                  U5      u  p#pEUSS nU " X#XV5      $ )z%Construct an _OpReply from raw bytes.   N)UNPACK_FROM)clsr   r   r   r  r  r2   s          rC   unpack_OpReply.unpack  s/     03s/C,!H	5_@@r.   )r   r2   r   r  )r   r>  r   r>  r  r>  r2   bytes)NN)r   Optional[int]r  Optional[Mapping[str, Any]]rA  list[bytes]
r   r  r   r   r  r  r  r  rA  zlist[dict[str, Any]]r   r   rA  dict[str, Any])rA  r   rA  r  )r   r  rA  r  )rT   rD  rE  rF  rG  rH  structStructunpack_fromr  OP_CODEr   r  r<   r  r  r  rI  r  classmethodr  rJ  rB   r.   rC   r  r  C  s    .FI--(44KG# [_*&*<W*	*\ $(&D37 %V V $V 1	V
 V 
V:"
   A Ar.   r  c                      \ rS rSrSrSr\R                  " S5      R                  r	Sr
SrSrSrSS	 jrS
0 4     SS jjrS
\S
S4         SS jjrSS jrSS jr\SS j5       r\SS j5       rSrg
)_OpMsgi  z"A MongoDB OP_MSG response message.)r   r   r  payload_documentz<IBir   r,   r-   i   c                    Xl         X l        g r   r   r'  )r  r   r'  s      rC   r   _OpMsg.__init__  s    
 0r.   Nc                f    [         R                  " [        U R                  5      U[        5      nU/$ )zX
cursor_id is ignored
user_fields is used to determine which fields must not be decoded
)r   _decode_selectiver   r'  r   )r  r   r  inflated_responses       rC   r  _OpMsg.raw_response  s3     !22D112KAX
 """r.   Fc                V    U(       a   e[         R                  " U R                  X#5      $ )aF  Unpack a OP_MSG command response.

:param cursor_id: Ignored, for compatibility with _OpReply.
:param codec_options: an instance of
    :class:`~bson.codec_options.CodecOptions`
:param user_fields: Response fields that should be decoded
    using the TypeDecoders from codec_options, passed to
    bson._decode_all_selective.
)r   r  r'  r  s        rC   r  _OpMsg.unpack_response  s&    " #""))$*?*?\\r.   c                &    U R                  US9S   $ )r  r  r   )r  )r  r   s     rC   r  _OpMsg.command_response  s    ##-#@CCr.   c                    U R                   $ r
  )r'  r#  s    rC   r  _OpMsg.raw_command_response  s    $$$r.   c                F    [        U R                  U R                  -  5      $ )r  )r  r   MORE_TO_COMEr#  s    rC   r  _OpMsg.more_to_come  s     DJJ!2!2233r.   c                <   U R                  U5      u  p#nUS:w  aD  X R                  -  (       a  [        SUS 35      eX R                  -  (       a  [        SUS 35      eUS:w  a  [        SUS 35      e[	        U5      US-   :w  a  [        S5      eUSS nU " X%5      $ )	z#Construct an _OpMsg from raw bytes.r   z+Unsupported OP_MSG flag checksumPresent: 0xxzUnsupported OP_MSG flags: 0xz#Unsupported OP_MSG payload type: 0x   z$Unsupported OP_MSG reply: >1 sectionN)r  CHECKSUM_PRESENTr    r6  rK   )r  r   r   first_payload_typefirst_payload_sizer'  s         rC   r  _OpMsg.unpack  s     9<8L5#5A:+++#&QRWXYQZ$[\\'''#&B5)$LMM""EFXYZE[ \]]s8)A-- FGGqr75++r.   r)  )r   r>  r'  r  )r   r  r  r  rA  r_  r  r  )rA  r  r  )r   r  rA  r&  )rT   rD  rE  rF  rG  rH  r   r!  r"  r  r#  r;  r6  EXHAUST_ALLOWEDr   r  r<   r  r  r  rI  r  r$  r  rJ  rB   r.   rC   r&  r&    s    ,MI--'33KG LO1 $(35# # 1# 
!	#  $(&D37 %] ] $] 1	]
 ] 
](D% 4 4 , ,r.   r&  z5dict[int, Callable[[bytes], Union[_OpReply, _OpMsg]]]_UNPACK_REPLYc                      \ rS rSrSrSrSrSr                                SS jrSS jr	SS jr
SS jrSS	 jr S     SS
 jjr S       SS jjrSrg)_Queryi  zA query operation.)r   dbr   ntoskiprL   fieldsr   rM   r   r   r   r   r   r   clientr   _as_commandexhaustNc                    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        Xl	        Xl
        Xl        Xl        Xl        Xl        SU l        S U l        UU l        g )Nr   )r   rC  r   rD  rL   rE  r   rM   r   r   r   r   r   rF  r   r   rG  rH  )r  r   rC  r   rD  rL   rE  r   rM   r   r   r   r   r   rF  r   rH  s                    rC   r   _Query.__init__*  si    & 
		*.(
$",	AEr.   c                    S U l         g r   rG  r#  s    rC   reset_Query.resetP  
    r.   c                8    U R                    SU R                   3$ Nr  rC  r   r#  s    rC   rU  _Query.namespaceS      ''!DII;''r.   c                6   SnU R                   (       d  SnO\UR                  S:  a  SnOIU R                  R                  (       d.  [	        SU R                  R
                  UR                  4-  5      eUR                  U R                  U R                  5        U$ )NFTrd   zDread concern level of %s is not valid with a max wire version of %d.)	rH  r   r   ok_for_legacyr   r   validate_sessionrF  r   )r  r   use_find_cmds      rC   use_command_Query.use_commandV  s    ||L""a'L""00$1484E4E4K4KTMbMb3cd 
 	dkk4<<8r.   c                (    XR                   4U l        g r   rC  rG  r  r   s     rC   update_command_Query.update_commandf      <r.   c                T   U R                   b  U R                   $ SU R                  ;   n[        U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  5      nU(       a  SU l        SU0nUR                  U5        U R                  (       ae  U R                  R                  USU R                   U5        U(       d6  U R                  R"                  (       d  U R                  R%                  XA5        UR'                  X@R                  U R(                  5        U(       a  UR+                  U R(                  US9  X@R,                  4U l         U R                   $ )z.Return a find command document for this query.r   explainFr   )rG  rL   r   r   rE  rD  r   r   r   r   r   r   r   r   add_server_api	_apply_torM   r   _update_read_concernsend_cluster_timerF  apply_timeoutrC  )r  r   rh  rb  r   s        rC   
as_command_Query.as_commandi  s;    '###		)/IIIIKKLLJJOOJJNNLL
 !DIc"CC <<LL""3t/C/CTJ4<<#>#>11#<sLL$++>t{{4<r.   c                   Xl         UR                  (       a  U R                  S-  nOU R                  nU R                  5       nU R                  nU(       aG  U R                  U5      S   n[        SUU R                  UU R                  UR                  S9u  pxpXxU	4$ U R                  S:H  =(       a    S=(       d    U R                  nU R                  (       a*  U(       a  [        U R                  U5      nOU R                  nUR                  (       a"  [        U[        5      (       d   e[!        Xa5      n[#        UUU R$                  UUU(       a  SOU R&                  U R                  UR                  S9$ )z:Get a query message, possibly setting the secondaryOk bit.r   r   r   r,   r-   N)rM   rH   r   rU  rL   ri  r   rC  r   r  r   r   r   	is_mongos
isinstancer
   rN   r   rD  rE  )r  rM   r   use_cmdr   r  rL   r   r   r   r  	ntoreturns               rC   get_message_Query.get_message  s4   
  /JJNEJJE^^yy??4(+D'."",,($JT D((
 OOq(.QA$//	::

I6	 JJ	>>dN3333-dDDLLD((	
 		
r.   )rG  r   r   rF  r   r   r   rC  rH  rE  r   r   r   rD  r   rM   r   rL   ) r   r>  rC  rR   r   rR   rD  r>  rL   Mapping[str, Any]rE  r  r   r   rM   r"   r   r>  r   r>  r   r&   r   r  r   r?  rF  r*   r   Optional[bool]rH  r  rA  rC  rA  rR   r   r)   rA  r  r   r  rA  rC  Fr   r)   rh  r  rA  ztuple[dict[str, Any], str])rM   r"   r   r)   ro  r  rA  tuple[int, bytes, int])rT   rD  rE  rF  rG  rH  conn_mgrr   r   rM  rU  rY  r^  ri  rq  rJ  rB   r.   rC   rB  rB    s&   I, HI$$ $ 	$
 $  $ ,$ $$ %$ $ $ "$ /$ 2$ %$  '!$" #$L ( ( @E% '% 8<% 	#% P X]2
*2
2E2
PT2
	2
 2
r.   rB  c                      \ rS rSrSrSrSr                        SS jrSS jrSS jr	SS jr
SS	 jr S     SS
 jjr S       SS jjrSrg)_GetMorei  zA getmore operation.)rC  r   rp  r   r   r   rM   r   rF  r|  rG  rH  r   r   c                    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        Xl	        S U l
        Xl        Xl        g r   )rC  r   rp  r   r   rM   r   rF  r   r|  rG  rH  r   )r  rC  r   rp  r   r   rM   r   rF  r   r|  rH  r   s                rC   r   _GetMore.__init__  sK     	""*.!2 AEr.   c                    S U l         g r   rL  r#  s    rC   rM  _GetMore.reset  rO  r.   c                8    U R                    SU R                   3$ rQ  rR  r#  s    rC   rU  _GetMore.namespace  rT  r.   c                    SnU R                   (       d  SnOUR                  S:  a  SnUR                  U R                  U R                  5        U$ )NFTrd   )rH  r   rW  rF  r   )r  r   ro  s      rC   rY  _GetMore.use_command  sC    ||G""a'Gdkk4<<8r.   c                (    XR                   4U l        g r   r\  r]  s     rC   r^  _GetMore.update_command  r`  r.   c                   U R                   b  U R                   $ [        U R                  U R                  U R                  U R
                  U R                  U5      nU R                  (       a(  U R                  R                  USU R                  U5        UR                  U5        UR                  X0R                  U R                  5        U(       a  UR                  U R                  SS9  X0R                  4U l         U R                   $ )z1Return a getMore command document for this query.NFrc  )rG  r   r   r   rp  r   r   r   re  rM   rd  rg  rF  rh  rC  )r  r   rh  r   s       rC   ri  _GetMore.as_command  s    
 '###3NNIINN""LL
 <<LL""3t/C/CTJC sLL$++>t{{5<r.   c           	        U R                  5       nUR                  nU(       a{  U R                  U5      S   nU R                  (       a"  U R                  (       a  [
        R                  nOSn[        XvU R                  SU R                  UR                  S9u  ppXU
4$ [        X@R                  U R                  U5      $ )zGet a getmore message.r   Nrl  )rU  r  ri  r|  rH  r&  r?  r   rC  r   r  rp  r   )r  dummy0r   ro  r  r   rL   r   r   r   r   r  s               rC   rq  _GetMore.get_message%  s     ^^&&??4(+D}}..'.TWWdD,>,>DD\D\($JT D((^^T^^SAAr.   )rG  rF  r   r   r   r|  r   rC  rH  r   rp  rM   r   N)rC  rR   r   rR   rp  r>  r   r>  r   r   rM   r"   r   r?  rF  r*   r   r  r|  r   rH  r  r   r   ru  rv  rw  rx  ry  rz  )r  r   r   r)   ro  r  rA  z0Union[tuple[int, bytes, int], tuple[int, bytes]])rT   rD  rE  rF  rG  rH  r   r   rM  rU  rY  r^  ri  rq  rJ  rB   r.   rC   r~  r~    s    I  D  	
  $ % 2 % )   : (	( @E ' 8< 	# 6 GLBB!4B?CB	9B Br.   r~  c                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )_RawBatchQueryi:  c                j   > [         TU ]  U5        UR                  S:  a  gU R                  (       d  ggNrd   TFrO  rY  r   rH  r  r   rS   s     rC   rY  _RawBatchQuery.use_command;  .    D!  A%r.   rB   rw  rT   rD  rE  rF  rY  rJ  ra  rb  s   @rC   r  r  :       r.   r  c                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ )_RawBatchGetMoreiF  c                j   > [         TU ]  U5        UR                  S:  a  gU R                  (       d  ggr  r  r  s     rC   rY  _RawBatchGetMore.use_commandG  r  r.   rB   rw  r  rb  s   @rC   r  r  F  r  r.   r  c                  `    \ rS rSr% SrS\S'   SS jr\SS j5       rSS jr	SS jr
SS	 jrS
rg)_CursorAddressiR  zEThe server address (host, port) of a cursor, with namespace property.r   _CursorAddress__namespacec                <    [         R                  X5      nX#l        U$ r   )tuple__new__r  )r  r1  rU  r  s       rC   r  _CursorAddress.__new__W  s    }}S*$r.   c                    U R                   $ )zThe namespace this cursor.)r  r#  s    rC   rU  _CursorAddress.namespace\  s     r.   c                @    / U QU R                   P7R                  5       $ r   )r  __hash__r#  s    rC   r  _CursorAddress.__hash__a  s#     *$)(()3355r.   c                    [        U[        5      (       a7  [        U 5      [        U5      :H  =(       a    U R                  UR                  :H  $ [        $ r   )rn  r  r  rU  NotImplementedr  others     rC   __eq___CursorAddress.__eq__f  s:    e^,,;%,.T4>>U__3TTr.   c                    X:X  + $ r   rB   r  s     rC   __ne___CursorAddress.__ne__k  s      r.   )__namespaceN)r1  r'   rU  rR   rA  r  rv  r@  )r  objectrA  r  )rT   rD  rE  rF  rG  __annotations__r  rI  rU  r  r  r  rJ  rB   r.   rC   r  r  R  s3    O
    6

!r.   r  r@  )rL   r^  rM   r"   rA  r^  )rV   	ExceptionrA  r  )rm   rR   rn   rs  ro   rs  rA  r  )NNN)r   rR   rL   rs  r   z1Optional[Union[Mapping[str, Any], Iterable[str]]]r   r>  r   r>  r   r  r   r  r   r&   r   r  r   r?  r   rt  rA  r  )r   r  r   rR   r   r  r   r  r   zOptional[Any]r   r)   rA  r  )rm   r>  r   r  r   .Union[SnappyContext, ZlibContext, ZstdContext]rA  tuple[int, bytes])rm   r>  r   r  rA  r  )r   r>  rn   rs  r   rR   r   !Optional[list[Mapping[str, Any]]]r   r   rA  ztuple[bytes, int, int])r   r>  rn   rs  r   rR   r   r  r   r   r   r  rA  tuple[int, bytes, int, int])r   r>  rn   rs  r   rR   r   r  r   r   rA  r  r   )r   r>  rn   r^  r   rR   rM   zOptional[_ServerMode]r   r   r   4Union[SnappyContext, ZlibContext, ZstdContext, None]rA  r  )r   r>  r   rR   r   r>  r   r>  r   rs  r   r  r   r   rA  ztuple[bytes, int])r   r>  r   rR   r   r>  r   r>  r   rs  r   r  r   r   r   r  rA  r{  )r   r>  r   rR   r   r>  r   r>  r   rs  r   r  r   r   rA  r{  )r   r>  r   rR   r   r>  r   r>  r   rs  r   r  r   r   r   r  rA  r{  )r   rR   r   r>  r   r>  rA  r  )
r   rR   r   r>  r   r>  r   r  rA  r  )r   rR   r   r>  r   r>  rA  r  )
r   rR   r   r>  r   r>  r   r  rA  r  )rm   rR   rp  r>  rq  r>  rA  r   )rm   r>  rn   rs  r   r_  r~  r  r   r   r   rL  r  r  rA  #tuple[list[Mapping[str, Any]], int])rm   r>  rn   rs  r   r_  r~  r  r   r   r   rL  rA  %tuple[bytes, list[Mapping[str, Any]]])rm   r>  rn   rs  r   r_  r~  r  r   r   r   rL  rA  *tuple[int, bytes, list[Mapping[str, Any]]])rU  rR   rm   r>  rn   r^  r   r_  r   r   r   rL  rA  r  )r  r  r  r  r  r  r~  r  r  r  rA  r>  )rn   rs  r  r  r  r  r~  r  r   r   r   r  r  r  rA  z<tuple[list[Mapping[str, Any]], list[Mapping[str, Any]], int])rn   rs  r  r  r  r  r~  r  r   r   r   r  rA  z>tuple[bytes, list[Mapping[str, Any]], list[Mapping[str, Any]]])rn   rs  r  r  r  r  r~  r  r   r   r   r  rA  Ctuple[int, bytes, list[Mapping[str, Any]], list[Mapping[str, Any]]])rn   r^  r  r  r  r  r   r   r   r  rA  r  )rU  rR   rm   r>  rn   r^  r   r_  r   r   r   rL  rA  r  )rU  rR   rm   r>  rn   r^  r   r_  r   r   r   rL  r  r  rA  r  )rG  
__future__r   r  r>   r   ior   r  typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   
bson.int64r   bson.raw_bsonr   r   r   r   pymongo.hellor   pymongo.monitoringr   pymongor   _use_cImportErrorpymongo.errorsr   r   r   r   r   r   r   r    pymongo.read_preferencesr!   r"   pymongo.compression_supportr#   r$   r%   pymongo.read_concernr&   pymongo.typingsr'   r(   r)   r*   r+   rA   r@   r  _INSERT_UPDATE_DELETE_EMPTYr  r  r  r   r  r  r  r   r<   r  rD   rN   rW   rZ   rs   r   r   r   r   r!  packr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _query_messager   r  r  r  r	  _get_more_messager  ry  r  rL  rd  rr  rm  r  r  r  r  rT  r  r  r  r  r  r  r  r  rg  r  r  r&  r#  r  r@  rB  r~  r  r  r  r  rB   r.   rC   <module>r     s   #    "
 
 
  < <   & .!F	 	 	 ASS0  		  


	
..1// 	
 CO!*C  ? 
0

"5@$O
!!.!8I!!J  #"
2 .204%)4
4
4 B4 	4
 4 4 4 4 +4 .4 #4 4n
  %	
   & "==499  +++&T++& }}W%** MM$$$	 --.33 ]]4 %%
444 4 ,	4
 4 4@/// / ,	/
 / 
8/ !/
=
=
= 
= ,	
=
 
= !
= 
$,, AE''%' ' +	'
 ' 
>' !'@  	
  0  >### # 	#
 # 0# # 
8# #$### # 	#
 # 0# # #" 
#22 AE  	
  0  
> ( --%**	[[[ [ 
8	[
 [[[),[9<[[ 
&88 AE		M	M	M 	M 
>		M
 	M  ^^[
 [
|4- 4n#!2 #0L&  AAA "A 
	A
 A 
A 
A )AH### "# 
	#
 # 
# +#" 
&==$$$ "$ 
	$
 $ 
$ 0$$/// "/ 
	/
 / 
/ 0/8 
//OEEE &E "	E
 E 
E 0E*:3 :z  --$- $- 
	-
 
- 	-`s+s+3s+ s+ 
	s+
 s+ 
!s+ 
s+ Bs+l3333 3 
	3
 3 
!3 D3&4434 4 
	4
 4 
!4 I4(??3? ? 
	?
 ? 
!? I?<S%S3S S 	S
 
!S IS.### &# "	#
 # 
# +# 
$-$K$K!JJJ &J "	J
 J 
J 
J )JZnA nAbQ, Q,j hoo
NNFMMHD t
 t
nrB rBj	V 		x 	!U !u8  Fs   T	 	TT