
    l8'h)                    	   U d Z ddlmZ ddlZddlZddlZddlmZ ddl	m
Z
mZmZmZmZmZmZmZmZ ddlZddlmZmZmZ ddlm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Z$ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0m1Z1 e
rddl2m3Z3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z<m=Z= dZ>dZ?dZ@dZAdZBdZCdZDdZEdZFdZGdZHdZIdZJeAdeBd eCd!iZKd"d#d$d%d&ZL ed'(      ZMd)eNd*<   dd+ZO	 	 	 	 	 	 dd,ZPdd-ZQdd.ZR	 	 	 	 	 	 	 	 dd/ZSdd0d1d2d3d4ZTd5d6d7d8d9d:d;d<d=d>d>d?d@ZU	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddAZV	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddBZW ej                  dC      j                  ZZdDZ[	 	 	 	 	 	 	 	 ddEZ\ ej                  dF      j                  Z]ddGZ^ ej                  dH      j                  Z_ ej                  dI      j                  Z` ej                  dJ      j                  Za	 	 	 	 	 	 	 	 	 	 	 	 ddKZb	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddLZc	 	 	 	 	 	 	 	 	 	 	 	 ddMZde$re#j                  Zd	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddNZe	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddOZf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddPZg	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddQZhe$re#j                  Zh	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddRZj ej                  dS      j                  ZkddTZl	 	 	 	 	 	 	 	 	 	 ddUZm	 	 	 	 	 	 	 	 ddVZne$re#j                  Zn	 d	 	 	 	 	 	 	 	 	 ddWZpeAdXeBdYeCdZiZq G d[ d\      Zr G d] d^er      Zs G d_ d`es      ZtddaZudbZv	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddcZw	 	 	 	 	 	 	 	 	 	 	 	 	 	 dddZxe$re#j                  Zx	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddeZy	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddfZze$re#j                  Zz	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddgZ{ G dh dier      Z|djZ}	 	 	 	 	 	 	 	 	 	 	 	 ddkZ~	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddlZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddmZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddnZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddoZ	 	 	 	 	 	 	 	 	 	 	 	 ddpZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddqZe$re#j                  Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddrZ G ds dt      Z G du dv      Zej                  ej                  ej                  ej                  iZdweNdx<    G dy dz      Z G d{ d|      Z G d} d~e      Z G d de      Z G d de      Zy# e%$ r dZ$Y ew xY w)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	bulkWrite)insertupdatedeleter5   replace)unicode_decode_error_handlerzCodecOptions[Mapping[str, Any]]_UNICODE_REPLACE_CODEC_OPTIONSc                 >    t        j                  t        t              S )z(Generate a pseudo random 32 bit integer.)randomrandint	MIN_INT32	MAX_INT32 r.   K/var/www/html/trade_iq/venv/lib/python3.12/site-packages/pymongo/message.py_randintrC   t   s    >>)Y//r.   c                    |j                   }|j                  }|r8|t        j                  j                   k7  st	        |      dkD  rd| vrd| i} || d<   | S )z-Add $readPreference to spec when appropriate.r,   $query$readPreference)modedocumentr!   SECONDARY_PREFERREDlen)specread_preferencerG   rH   s       rB   _maybe_add_read_preferencerM   y   s`     D''H ;;@@@CMTUDU4d#D"*Kr.   c                F    t        |       | j                  j                  dS )z<Convert an Exception into a failure document for publishing.)errmsgerrtype)str	__class____name__	exceptions    rB   _convert_exceptionrV      s    )n1D1D1M1MNNr.   c                \    t        |       | j                  | j                  j                  dS )zmConvert an Exception into a failure document for publishing,
    for use in client-level bulk write API.
    )rO   coderP   )rQ   rX   rR   rS   rT   s    rB   _convert_client_bulk_exceptionrY      s+    
 i.&&// r.   c                   |j                  dd      }d|d}|j                  d|j                  dd            }|rG|j                  d      r|d	dd
id|d<   n*d|j                  dd      |d}d|v r|d   |d<   |g|d<   |S | dk(  rt        |d         |d<   |S | dk(  rbd|v rd|d   dg|d<   |S |j                  d      du r=|dk(  r8|d   d   }|d   j                  d|d   j                  d            }d|dg|d<   |S )z6Convert a legacy write result to write command format.nr   r,   )okr[   rO   err wtimeout@   T)rO   rX   errInfowriteConcernErrorrX      )indexrX   rO   ra   writeErrorsr6   r2   r7   upserted)rd   _idupdatedExistingFr3   urg   q)getrJ   )		operationcommandresultaffectedresrO   errorr7   rg   s	            rB   _convert_write_resultrr      sU   
 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.   rc             )tailableoplogReplaynoCursorTimeout	awaitDataallowPartialResultsfiltersorthintcommentmaxScan	maxTimeMSmaxmin	returnKeyshowRecordIdsnapshot)rE   z$orderbyz$hintz$commentz$maxScanz
$maxTimeMSz$maxz$minz
$returnKeyz$showRecordIdz$showDiskLocz	$snapshotc                h   d| i}d|v rr|j                  |j                         D cg c]  \  }}|t        v rt        |   |fn||f c}}       d|v r|j                  d       d|v r|j                  d       n||d<   |r||d<   |r||d<   |rt	        |      |d<   |d	k  rd
|d<   |r||d<   |j
                  r|	r|	j                  s|j                  |d<   |r||d<   |
|
|d<   |r>|j                  t        j                         D cg c]  \  }}||z  s|d
f c}}       |S c c}}w c c}}w )z!Generate a find command document.findrE   $explainrF   r{   
projectionskiplimitr   TsingleBatch	batchSizereadConcern	collationallowDiskUse)	r7   items
_MODIFIERSpopabslevelin_transactionrH   _OPTIONS)collrK   r   r   r   
batch_sizeoptionsread_concernr   sessionallow_disk_usecmdkeyvalopts                  rB   _gen_find_commandr      sV    "4.C4

 !%

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

0@RHCGcMS$KRSJ?: Ss   !D(

D.
D.
c                X    | |d}|r||d<   |||d<   ||j                   dk\  r||d<   |S )z$Generate a getMore command document.)getMore
collectionr   r   	   r~   )max_wire_version)	cursor_idr   r   max_await_time_msr~   connr   s          rB   _gen_get_more_commandr     sL     '0tDC%K$,Kt449 IJr.   z<iiiiiiB   c           
         |j                  |      }t               }t        t        t	        |      z   |dd| t	        |      |j
                        }|||z   fS )zDTakes message data, compresses it, and adds an OP_COMPRESSED header.r   i  )compressrC   _pack_compression_header_COMPRESSION_HEADER_SIZErJ   compressor_id)rl   datactx
compressed
request_idheaders         rB   	_compressr   "  s]     d#JJ% 3z?2	D	F v
***r.   z<iiiic                X    t               }t        dt        |      z   |d|       }|||z   fS )ztTakes message data and adds a message header based on the operation.

    Returns the resultant message string.
    rs   r   )rC   _pack_headerrJ   )rl   r   ridmessages       rB   __pack_messager   8  s2    
 *C2D	>39=G$r.   z<iz<IBz<Bc                   t        |d|      }t        | d      }t        |      }d}|r|}t        d      }	t	        |      }
|D cg c]  }t        |d|       }}t        |
      t        d |D              z   dz   }t        |      }||z  }t        d |D              }|||	||
g|}n||g}dj                  |      ||fS c c}w )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  2   K   | ]  }t        |        y wNrJ   .0docs     rB   	<genexpr>z$_op_msg_no_header.<locals>.<genexpr>]  s     !Cs#c(!C      c              3  2   K   | ]  }t        |        y wr   r   r   s     rB   r   z$_op_msg_no_header.<locals>.<genexpr>`  s     <3s8<r   r.   )	r   _pack_op_msg_flags_typerJ   
_pack_byter   sum	_pack_intr   join)flagsrm   
identifierdocsoptsencoded
flags_type
total_sizemax_doc_sizetype_onecstringr   encoded_docssizeencoded_sizer   s                   rB   _op_msg_no_headerr   G  s     GUD1G(2JWJLd&a= ,CGHCc5$7HH7|c!Cl!CCCaG d
<|<<GX|WT|TG$88D>:|33 Is   C c                T    t        | ||||      \  }}}t        d||      \  }	}|	|||fS )zInternal OP_MSG message helper.  )r   r   )
r   rm   r   r   r   r   msgr   max_bson_sizer   s
             rB   _op_msg_compressedr   g  s@     &7ugzSWY]%^"C]sC(HCZ..r.   c                R    t        | ||||      \  }}}t        d|      \  }}	||	||fS )z*Internal compressed OP_MSG message helper.r   )r   r   )
r   rm   r   r   r   r   r   r   r   
op_messages
             rB   _op_msg_uncompressedr   u  s?     '8w
TXZ^&_#D*m+D$7J
z:}<<r.   c                P   ||d<   |d|vr|j                   r|j                  |d<   t        t        |            }	 t        |   }|j                  |      }	 |rt        | |||||      |r|||<   S S t        | ||||      |r|||<   S S # t        $ r d}d}Y Aw xY w# |r|||<   w w xY w)zGet a OP_MSG message.$dbNrF   r^   )	rG   rH   nextiter
_FIELD_MAPr   KeyErrorr   r   )	r   rm   dbnamerL   r   r   namer   r   s	            rB   _op_msgr     s     GEN"'8'G)8)A)AG%&WD%
{{:&'%eWj$cR "&GJ  $E7JdK "&GJ   
 "&GJ s#   B B 1B BB
B%c                
   t        |d|      }|rt        |d|      }nd}t        t        |      t        |            }	dj                  t	        |       t        j                  |      t	        |      t	        |      ||g      |	fS )zGet an OP_QUERY message.Fr.   )r   r   rJ   r   r   bsonr   )
r   collection_namenum_to_skipnum_to_returnqueryfield_selectorr   r   efsr   s
             rB   _query_implr     s     E5$/GNE48Gc#h/M'"##O4+&-(		
 	 r.   c           	     T    t        | ||||||      \  }}	t        d||      \  }
}|
||	fS )z)Internal compressed query message helper.  )r   r   )r   r   r   r   r   r   r   r   op_queryr   r   r   s               rB   _query_compressedr     sD     *+}e^UYHm x-HC]""r.   c           	     R    t        | ||||||      \  }}t        d|      \  }	}
|	|
|fS )zInternal query message helper.r   )r   r   )r   r   r   r   r   r   r   r   r   r   r   s              rB   _query_uncompressedr     sB     *+}e^UYHm dH-HC]""r.   c           
     L    |rt        | |||||||      S t        | ||||||      S )zGet a **query** message.)r   r   )r   r   r   r   r   r   r   r   s           rB   _queryr     sF      _k=%Y]_b
 	
 +}e^UY r.   z<qc                ~    dj                  t        t        j                  |       t	        |      t        |      g      S )zGet an OP_GET_MORE message.r.   )r   _ZERO_32r   r   r   _pack_long_longr   r   r   s      rB   _get_more_implr    s9    880m$I&		
 r.   c                2    t        dt        | ||      |      S )z+Internal compressed getMore message helper.  )r   r  r   r   r   r   s       rB   _get_more_compressedr    s     T>/=)TVYZZr.   c                0    t        dt        | ||            S )z Internal getMore message helper.r  )r   r  r   s      rB   _get_more_uncompressedr    s     $y YZZr.   c                <    |rt        | |||      S t        | ||      S )zGet a **getMore** message.)r  r  r  s       rB   	_get_morer	  $  s'     #O]IsSS!/=)LLr.   s
   documents s   updates s   deletes c                      e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZedd       Zedd       Zedd       Z	edd       Z
ddZdd	Zy
)_BulkWriteContextBasez]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	                @   || _         || _        || _        || _        |j                  | _        || _        t        | j                     | _        t        j                  j                         | _        || _        t        |j                        | _        || _        || _        y 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	            rB   __init__z_BulkWriteContextBase.__init__L  s     %	!
" 55			*
"++//1T556
r.   c                .    | j                   j                  S )z#A proxy for SockInfo.max_bson_size.)r   r   r  s    rB   r   z#_BulkWriteContextBase.max_bson_sized  s     yy&&&r.   c                x    | j                   r| j                  j                  dz
  S | j                  j                  S )z&A proxy for SockInfo.max_message_size.rs   )r   r   max_message_sizer   s    rB   r"  z&_BulkWriteContextBase.max_message_sizei  s0     ==99--22yy)))r.   c                .    | j                   j                  S )z*A proxy for SockInfo.max_write_batch_size.)r   max_write_batch_sizer   s    rB   r$  z*_BulkWriteContextBase.max_write_batch_sizeq  s     yy---r.   c                    | j                   S )z:The maximum size of a BSON command before batch splitting.)r   r   s    rB   max_split_sizez$_BulkWriteContextBase.max_split_sizev  s     !!!r.   c                    | j                   j                  ||| j                  || j                  j                  | j                  j
                  | j                  | j                  j                  | j                  	       y)z Publish a CommandSucceededEvent.r  N)	r  publish_command_successr   r   addressserver_connection_idr  
service_idr  )r  r   replydurations       rB   _succeedz_BulkWriteContextBase._succeed{  s^    ..IIIIII**JJII  ,, 	/ 
	
r.   c                    | j                   j                  ||| j                  || j                  j                  | j                  j
                  | j                  | j                  j                  | j                  	       y)zPublish a CommandFailedEvent.r(  N)	r  publish_command_failurer   r   r*  r+  r  r,  r  )r  r   failurer.  s       rB   _failz_BulkWriteContextBase._fail  s^    ..IIIIII**JJII  ,, 	/ 
	
r.   Nr  rQ   r  rQ   r   r)   r  intr  r   r    Optional[_AgnosticClientSession]r  r5  r  r   returnr5  )r   r5  r-  r+   r.  datetime.timedeltar8  None)r   r5  r2  r+   r.  r9  r8  r:  )rS   
__module____qualname____doc__	__slots__r  propertyr   r"  r$  r&  r/  r3  rA   r.   rB   r  r  :  s    gI  "	
  # 2  0 ' ' * * . . " "

r.   r  c                  t     e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 ddZ xZS )	_BulkWriteContextz]A wrapper around AsyncConnection/Connection for use with the collection-level bulk write API.rA   c	           
     2    t         	|   ||||||||       y r   superr  )
r  r  r  r   r  r  r   r  r  rR   s
            rB   r  z_BulkWriteContext.__init__  s*     			
r.   c                    | j                   dz   }t        || j                  ||| j                  |       \  }}}|st	        d      |||fS )N.$cmdcannot do an empty bulk write)r  _do_batched_op_msgr  r  r   )r  r   r   	namespacer   r   to_sends          rB   batch_commandz_BulkWriteContext.batch_command  sV     LL7*	#5t||S$

D$
 
C "#BCC3''r.   c           	        ||| j                   <   | j                  j                  || j                  || j                  j
                  | j                  j                  | j                  | j                  j                         |S )Publish a CommandStartedEvent.)	r  r  publish_command_startr  r   r*  r+  r  r,  )r  r   r   r   s       rB   _startz_BulkWriteContext._start  se     DJJ,,LLIIII**JJII  	
 
r.   r4  )r   MutableMapping[str, Any]r   list[Mapping[str, Any]]r8  zAtuple[int, Union[bytes, dict[str, Any]], list[Mapping[str, Any]]])r   rP  r   r5  r   rQ  r8  rP  	rS   r;  r<  r=  r>  r  rK  rO  __classcell__rR   s   @rB   rA  rA    s    gI

 
 "	

 
 #
 2
 
 
,	(+	(3J	(	J	(+9<D[	!r.   rA  c                  6    e Zd ZdZ	 	 	 	 	 	 ddZedd       Zy)_EncryptedBulkWriteContextrA   c                    | j                   dz   }t        || j                  ||| j                  |       \  }}|st	        d      |j                  dd      dz   }t        t        |      |d  t              }d||fS )NrF  rG  r0   r   r   )	r  _encode_batched_write_commandr  r  r   rd   r   
memoryviewr   )r  r   r   rI  r   rJ  	cmd_startoutgoings           rB   rK  z(_EncryptedBulkWriteContext.batch_command  s     LL7*	4t||S$

D
W "#BCC IIgq)A-	 C!<>VW8W$$r.   c                    t         S )z Reduce the batch splitting size.)_MAX_SPLIT_SIZE_ENCr   s    rB   r&  z)_EncryptedBulkWriteContext.max_split_size  s
     #"r.   N)r   rP  r   rQ  r8  z3tuple[int, dict[str, Any], list[Mapping[str, Any]]]r7  )rS   r;  r<  r>  rK  r?  r&  rA   r.   rB   rV  rV    s8    I%+%3J%	<% # #r.   rV  c                H    | dk(  rt        d||fz        t        | d      )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   )rl   doc_sizemax_sizes      rB   _raise_document_too_largerb    s@    H "8,-
 	
 ).IJKKr.   i    c                   |j                   }|j                  }|j                  }	|rdnd}
|j                  |
       |j                  d       |j                  t	        |d|             |j                  d       |j                         }|j                  d       	 |j                  t        |           g }d}|D ]  }t	        |d|      }t        |      }|j                         |z   }|dk(  xr ||	kD  }| xr ||kD  }|s|r6t        t        j                               |    }t        |t        |      |       ||	kD  r n0|j                  |       |j                  |       |d	z  }||k(  s n |j                         }|j                  |       |j                  t!        ||z
               ||fS # t        $ r t        d      dw xY w)
zCreate a batched OP_MSG write.r1         r0   F   Unknown commandNr   r,   )r   r$  r"  writer   tell_OP_MSG_MAPr   r   rJ   listr   keysrb  appendseekr   )rl   rm   r   ackr   r   bufr   r$  r"  r   size_locationrJ  idxr   value
doc_lengthnew_message_sizedoc_too_largeunacked_doc_too_largewrite_oplengths                         rB   _batched_op_msg_implry    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   F1 1Gc           	     b    t               }t        | ||||||      \  }}|j                         |fS )zOEncode the next batched insert, update, or delete operation
    as OP_MSG.
    )_BytesIOry  getvalue)	rl   rm   r   rn  r   r   ro  rJ  _s	            rB   _encode_batched_op_msgr~  A  s7     *C%i$T3PSTJGQ<<>7""r.   c                    t        | |||||      \  }}|j                  j                  J t        d||j                  j                        \  }}	||	|fS )z]Create the next batched insert, update, or delete operation
    with OP_MSG, compressed.
    r   )r~  r   r  r   )
rl   rm   r   rn  r   r   r   rJ  r   r   s
             rB   _batched_op_msg_compressedr  V  s\     +9gtS$PSTMD'88''333dCHH,H,HIOJsG##r.   c           	     p   t               }|j                  t               |j                  d       t        | ||||||      \  }}|j	                  d       t               }	|j                  t        |	             |j	                  d       |j                  t        |             |	|j                         |fS )z"OP_MSG implementation entry point.         r   r   )r{  rg  _ZERO_64ry  rm  rC   r   r|  )
rl   rm   r   rn  r   r   ro  rJ  rx  r   s
             rB   _batched_op_msgr  h  s     *C IIhII12*9gtS$PSUXYOGV HHQKJIIi
#$HHQKIIi s||~w..r.   c                    | j                  dd      d   |d<   d|v rt        |d   j                  dd            }nd}|j                  j                  rt        ||||||      S t        ||||||      S )zRCreate the next batched insert, update, or delete operation
    using OP_MSG.
    .r,   r   r   writeConcernwT)splitr  rk   r   r  r  r  )rI  rl   rm   r   r   r   rn  s          rB   rH  rH    s}     __S!,Q/GEN 7>*..sA67
xx##))WdCsSS9gtS$DDr.   c                  x     e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZ xZS )	_ClientBulkWriteContextzYA wrapper around AsyncConnection/Connection for use with the client-level bulk write API.rA   c           
     2    t         |   ||||||d|       y )Nr   rC  )	r  r  r  r   r  r  r   r  rR   s	           rB   r  z _ClientBulkWriteContext.__init__  s*     			
r.   c                d    t        |||| j                  |       \  }}}}|st        d      ||||fS )NrG  )_client_do_batched_op_msgr  r   )r  r   
operations
namespacesr   r   to_send_ops
to_send_nss           rB   rK  z%_ClientBulkWriteContext.batch_command  sG     4MZT4
0
Cj "#BCC3Z77r.   c           	         ||d<   ||d<   | j                   j                  || j                  || j                  j                  | j                  j
                  | j                  | j                  j                         |S )rM  opsnsInfo)r  rN  r  r   r*  r+  r  r,  )r  r   r   op_docsns_docss        rB   rO  z_ClientBulkWriteContext._start  sj     E
H,,LLIIII**JJII  	
 
r.   )r  rQ   r  rQ   r   r)   r  r5  r  r   r   r6  r  r   )r   rP  r  #list[tuple[str, Mapping[str, Any]]]r  	list[str]r8  zZtuple[int, Union[bytes, dict[str, Any]], list[Mapping[str, Any]], list[Mapping[str, Any]]])
r   rP  r   r5  r  rQ  r  rQ  r8  rP  rR  rT  s   @rB   r  r    s    cI

 
 "	

 
 #
 2
 
*8%8 88 	8
 
d8%  )	
 ) 
"r.   r  i  c                   |rdnd}|j                  |       |j                  d       |j                  |        |j                  d       |j                         }|j                  d       |j                  d       |D ]  }|j                  |        |j                         }|j                         }	|j                  |       |j                  t        |	|z
               |j                  |       |j                  d       |j                         }|j                  d       |j                  d       |D ]  }
|j                  |
        |j                         }	|j                  |       |j                  t        |	|z
               |	S )Nr1   rd  r0   re  s   ops s   nsInfo )rg  rh  rm  r   )command_encodedto_send_ops_encodedto_send_ns_encodedrn  ro  r   rp  
op_encodedresume_locationrx  
ns_encodeds              rB   _client_construct_op_msgr    sG    $',?EIIe IIgIIo IIgHHJMII!"IIj) 
		*hhjOXXZFHH]IIi./0HH_ IIgHHJMII!"IIm( 
		* XXZFHH]IIi./0Mr.   c                   	 	 	 	 	 	 	 	 dd}|j                   }|j                  }	|j                  }
t        | d|      }|s |dt	        |      |t
        z          g d}| j                  d      r|j                  d       | j                  d      r|j                  d       | j                  d      r|j                  d       |D ci c]  }|| |   
 }}t	        t        |d|            }|
t        |z   z
  }i }g }g }g }g }d}d}d}t        ||      D ]Q  \  \  }}}|}|d	k(  r%|s#t	        t        |d
   d|            } ||||       |dk(  r'd}|s#t	        t        |d   d|            } ||||       d}d}||vrd|i}t	        |      } | ||<   ||   ||<   t        |d|      }!t	        |!      }"|rt        |d|      }#t	        |#      }|s |||"|t
        z          ||z   |"z   |z   }$|$|kD  r|dk(  rt        ||"|t
        z           n_|j                  |       |j                  |!       ||"z  }|r'|j                  |       |j                  #       ||z  }|dz  }||	k(  sR n t        |||||      }%|||%fS c c}w )z:Create a batched OP_MSG write for client-level bulk write.c                *    ||kD  rt        | ||       y y r   )rb  )r  r`  r   s      rB   _check_doc_size_limitsz;_client_batched_op_msg_impl.<locals>._check_doc_size_limits  s    
 e%gx? r.   Fr5   )r5   
errorsOnlyorderedbypassDocumentValidationr~   letr   r6   rH   r9   r7   
updateModsNnsr,   )r  rQ   r`  r5  r   r5  r8  r:  )r   r$  r"  r   rJ   _COMMAND_OVERHEADrk   rl  _OP_MSG_OVERHEADziprb  r  )&rm   r  r  rn  r   r   ro  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_lengthrq  real_op_typeop_docrI  r  r`  ns_doc	ns_lengthnew_ns_indexop_doc_encoded	op_lengthns_doc_encodedrt  rx  s&                                         rB   _client_batched_op_msg_implr    s.   @@@ @ 
	@ %%M33++#GUD9O {C,@-RcBcd ;M{{-.78{{9Y'{{5U#5BCcWS\)CC}-=udKL /2BEY2YZG+-K*,J')&(O
C-0Z-H 8)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8v &,.@#sF 
F**] Ds   I>c           	     f    t               }t        | ||||||      \  }}}	|j                         ||fS )zLEncode the next batched client-level bulkWrite
    operation as OP_MSG.
    )r{  r  r|  )
rm   r  r  rn  r   r   ro  r  r  r}  s
             rB   _client_encode_batched_op_msgr    s@     *C!<ZdC"KQ <<>;
22r.   c                    t        | |||||      \  }}}|j                  j                  J t        d||j                  j                        \  }	}
|	|
||fS )zZCreate the next batched client-level bulkWrite operation
    with OP_MSG, compressed.
    r   )r  r   r  r   )rm   r  r  rn  r   r   r   r  r  r   r   s              rB   !_client_batched_op_msg_compressedr    sf     %BZdC%!D+z 88''333dCHH,H,HIOJsK33r.   c           	     t   t               }|j                  t               |j                  d       t        | ||||||      \  }}}	|j	                  d       t               }
|j                  t        |
             |j	                  d       |j                  t        |	             |
|j                         ||fS )z=OP_MSG implementation entry point for client-level bulkWrite.r  r   r   )r{  rg  r  r  rm  rC   r   r|  )rm   r  r  rn  r   r   ro  r  r  rx  r   s              rB   _client_batched_op_msgr    s     *C IIhII12&AZdC'#KV
 HHQKJIIi
#$HHQKIIi s||~{J>>r.   c                    d| d<   d| v rt        | d   j                  dd            }nd}|j                  j                  rt	        | |||||      S t        | |||||      S )zOCreate the next batched client-level bulkWrite
    operation using OP_MSG.
    adminr   r  r  r,   T)r  rk   r   r  r  r  )rm   r  r  r   r   rn  s         rB   r  r    sp     GEN 7>*..sA67
xx##0*jRUW[]`aa!':z3cRRr.   c           	     b    t               }t        | ||||||      \  }}|j                         |fS )z:Encode the next batched insert, update, or delete command.)r{  _batched_write_command_implr|  )	rI  rl   rm   r   r   r   ro  rJ  r}  s	            rB   rY  rY    s9     *C,Y	7DRVX[]`aJGQ<<>7""r.   c                   |j                   }|j                  }|t        z   }	|j                  }
|j	                  t
               |j	                  | j                  d             |j	                  t               |j	                  t               |j                         }|j	                  t        j                  |             |j                  dd       |j                          	 |j	                  t        |          |j                         dz
  }g }d}|D ]  }t!        |      j                  d      }t#        |d|      }t%        |      |	kD  }|r6t'        t(        j+                               |   }t-        |t%        |      |       |d	k\  xr+ |j                         t%        |      z   t%        |      z   |
k\  }||k\  }|s|r ne|j	                  t.               |j	                  |       |j	                  t               |j	                  |       |j1                  |       |d	z  } |j	                  t2               |j                         }|j                  |       |j	                  t5        ||z
  d	z
               |j                  |       |j	                  t5        ||z
               ||fS # t        $ r t        d      dw xY w)
z(Create a batched OP_QUERY write command.utf8rX  r-   rf  Nr   r   Fr,   )r   r$  r  r&  rg  r   encode_ZERO_8_SKIPLIMrh  r   rm  truncate_OP_MAPr   r   rQ   r   rJ   rj  r   rk  rb  _BSONOBJrl  _ZERO_16r   )rI  rl   rm   r   r   r   ro  r   r$  max_cmd_sizer&  command_start
list_startrJ  rq  r   r   rr  ru  rw  enough_dataenough_documentsrx  s                          rB   r  r    sU    %%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6*		(		#		'		%sq'. IIh XXZFHHZIIi+a/01HH]IIi./0F?O  <01t;<s   $J0 0Kc                      e Zd ZdZdZ ej                  d      j                  ZdZ	ddZ
	 d	 	 	 	 	 ddZdeddf	 	 	 	 	 	 	 	 	 dd	Zdd
ZddZedd       Zedd       Zy)_OpReplyz$A MongoDB OP_REPLY response message.)r   r   number_returnedr2   z<iqiir,   c                N    || _         t        |      | _        || _        || _        y r   )r   r   r   r  r2   )r  r   r   r  r2   s        rB   r  z_OpReply.__init__G  s$    
y)."r.   Nc                   | j                   dz  r&|t        d      d|fz  }d|dd}t        |d|      | j                   dz  rt        j                  | j
                        j                         }|j                  dd       |d	   j                  t        j                        rt        |d	   |      |j                  d
      dk(  r.d}t        |j                  d	|      |j                  d
      |      t        d|j                  d	      z  |j                  d
      |      | j
                  r| j
                  gS g S )a  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\   rO   rX   r-   r\   z$errrX   2   zoperation exceeded time limitzdatabase error: %s)r   r    r   r   BSONr2   decode
setdefault
startswithr   LEGACY_ERRORr   rk   r   r   )r  r   user_fieldsr   errobjerror_objectdefault_msgs          rB   raw_responsez_OpReply.raw_responseM  s>    ::> #$HII 4ylBCb9F b&11ZZ!^!%4>>!:!A!A!CL##D!,F#..{/G/GH%l6&:LII!!&)R/=& $$V[9<;K;KF;SUa  #$|'7'7'??  ( 
 >>NN##	r.   Fc                    | j                  |       |r t        j                  | j                  |      S t        j                  | j                  ||      S )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        rB   unpack_responsez_OpReply.unpack_responsey  sC    0 	)$??4>>=AA))$..-UUr.   c                R    | j                  |      }| j                  dk(  sJ |d   S )Unpack a command response.r  r,   r   )r  r  )r  r  r   s      rB   command_responsez_OpReply.command_response  s2    ##-#@##q(((Awr.   c                    t         z)Return the bytes of the command response.)NotImplementedErrorr   s    rB   raw_command_responsez_OpReply.raw_command_response  s
     "!r.   c                     y)+Is the moreToCome bit set on this response?FrA   r   s    rB   more_to_comez_OpReply.more_to_come  s     r.   c                N    | j                  |      \  }}}}|dd } | ||||      S )z%Construct an _OpReply from raw bytes.   N)UNPACK_FROM)clsr   r   r   r}  r  r2   s          rB   unpackz_OpReply.unpack  s7     03s/C,y!_H	5)_i@@r.   )r   r5  r   r5  r  r5  r2   bytes)NN)r   Optional[int]r  Optional[Mapping[str, Any]]r8  list[bytes]
r   r  r  r   r  r   r  r  r8  zlist[dict[str, Any]]r  r   r8  dict[str, Any])r8  r   r8  r  )r   r  r8  r  )rS   r;  r<  r=  r>  structStructunpack_fromr  OP_CODEr  r  r;   r  r  r  r?  r  classmethodr  rA   r.   rB   r  r  ?  s    .FI&--(44KG# [_*&*<W*	*\ $(&D37 %V V $V 1	V
 V 
V:"
   A Ar.   r  c                      e Zd ZdZdZ ej                  d      j                  ZdZ	dZ
dZdZddZd	i f	 	 	 	 	 dd
Zd	ed	df	 	 	 	 	 	 	 	 	 ddZddZddZedd       Zedd       Zy	)_OpMsgz"A MongoDB OP_MSG response message.)r   r   r  payload_documentz<IBir   r,   r-   i   c                     || _         || _        y r   )r   r  )r  r   r  s      rB   r  z_OpMsg.__init__  s    
 0r.   Nc                d    t        j                  t        | j                        |t              }|gS )zp
        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       rB   r  z_OpMsg.raw_response  s3     !22D112KAX
 """r.   Fc                L    |rJ t        j                  | j                  ||      S )a~  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        rB   r  z_OpMsg.unpack_response  s)    " #""))$*?*?P[\\r.   c                ,    | j                  |      d   S )r  r  r   )r  )r  r  s     rB   r  z_OpMsg.command_response  s    ##-#@CCr.   c                    | j                   S r  )r  r   s    rB   r  z_OpMsg.raw_command_response  s    $$$r.   c                F    t        | j                  | j                  z        S )r  )r  r   MORE_TO_COMEr   s    rB   r  z_OpMsg.more_to_come  s     DJJ!2!2233r.   c                *   | j                  |      \  }}}|dk7  r<|| j                  z  rt        d|d      || j                  z  rt        d|d      |dk7  rt        d|d      t	        |      |dz   k7  rt        d      |dd } | ||      S )	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    r  rJ   )r  r   r   first_payload_typefirst_payload_sizer  s         rB   r  z_OpMsg.unpack  s     9<8L5!#5A:s+++#&QRWXYQZ$[\\s'''#&B5)$LMM""EFXYZE[ \]]s8)A-- FGGqr75*++r.   )r   r5  r  r  )r   r  r  r   r8  rQ  r  r  )r8  r  r  )r   r  r8  r  )rS   r;  r<  r=  r>  r  r  r  r  r	  r  r  EXHAUST_ALLOWEDr  r  r;   r  r  r  r?  r  r
  r  rA   r.   rB   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                      e Zd ZdZdZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZ	ddZ
ddZ	 d	 	 	 	 	 dd	Z	 d	 	 	 	 	 	 	 dd
Zy)_QueryzA query operation.)r   dbr   ntoskiprK   fieldsr  rL   r   r   r   r   r   r   clientr   _as_commandexhaustNc                    || _         || _        || _        || _        || _        || _        || _        || _        || _        |	| _	        |
| _
        || _        || _        || _        || _        d| _        d | _        || _        y )Nr   )r   r!  r   r"  rK   r#  r  rL   r   r   r   r   r   r$  r   r   r%  r&  )r  r   r!  r   r"  rK   r#  r  rL   r   r   r   r   r   r$  r   r&  s                    rB   r  z_Query.__init__&  s    & 
		*.(
$",	AEr.   c                    d | _         y r   r%  r   s    rB   resetz_Query.resetL  
    r.   c                8    | j                    d| j                   S Nr  r!  r   r   s    rB   rI  z_Query.namespaceO      ''!DII;''r.   c                    d}| j                   sd}nV|j                  dk\  rd}nD| j                  j                  s.t	        d| j                  j
                  |j                  fz        |j                  | j                  | j                         |S )NFTrc   zDread concern level of %s is not valid with a max wire version of %d.)	r&  r   r   ok_for_legacyr   r   validate_sessionr$  r   )r  r   use_find_cmds      rB   use_commandz_Query.use_commandR  s    ||L""a'L""00$1484E4E4K4KTMbMb3cd 
 	dkk4<<8r.   c                *    || j                   f| _        y r   r!  r%  r  r   s     rB   update_commandz_Query.update_commandb      <r.   c                *   | j                   | j                   S d| j                  v }t        | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                        }|rd| _        d|i}|j                  |       | j                  r\| j                  j                  |d| j                   |       |s2| j                  j"                  s| j                  j%                  ||       |j'                  || j                  | j(                         |r|j+                  | j(                  |       || j,                  f| _         | j                   S )z.Return a find command document for this query.r   explainFr   )r%  rK   r   r   r#  r"  r   r   r   r   r   r   r   r   add_server_api	_apply_torL   r   _update_read_concernsend_cluster_timer$  apply_timeoutr!  )r  r   rA  r;  r   s        rB   
as_commandz_Query.as_commande  sA    '###		)/IIIIKKLLJJOOJJNNLL
 !DIc"CC <<LL""3t/C/CTJ4<<#>#>11#t<sDLL$++>t{{4<r.   c           
        || _         |j                  r| j                  dz  }n| j                  }| j                         }| j                  }|rM| j                  |      d   }t        d|| j                  || j                  |j                        \  }}}	}
|||	fS | j                  dk(  xr dxs | j                  }| j                  r%|rt        | j                  |      }n| j                  }|j                  rt        |t              sJ t!        ||      }t#        ||| j$                  |||rdn| j&                  | j                  |j                        S )z:Get a query message, possibly setting the secondaryOk bit.r   r   r   r,   r-   N)rL   rG   r   rI  rK   rB  r   r!  r  r  r   r   r   	is_mongos
isinstancer
   rM   r   r"  r#  )r  rL   r   use_cmdr   r  rK   r   r   r   r}  	ntoreturns               rB   get_messagez_Query.get_message  s;   
  /JJNEJJE^^yy??4(+D'."",,($JT1 sD((
 OOq(.QA$//	::

I6	 JJ	>>dN333-dODDLLD((	
 		
r.   ) r   r5  r!  rQ   r   rQ   r"  r5  rK   Mapping[str, Any]r#  r   r  r   rL   r"   r   r5  r   r5  r   r&   r   r   r   r6  r$  r*   r   Optional[bool]r&  r  r8  r:  r8  rQ   r   r)   r8  r  r   r  r8  r:  Fr   r)   rA  r  r8  ztuple[dict[str, Any], str])rL   r"   r   r)   rG  r  r8  tuple[int, bytes, int])rS   r;  r<  r=  r>  conn_mgrr   r  r*  rI  r4  r8  rB  rI  rA   r.   rB   r   r   
  s!   I, HI$$ $ 	$
 $  $ ,$ $$ %$ $ $ "$ /$ 2$ %$  '!$" #$L ( ( @E% '% 8<% 	#% P X]2
*2
2E2
PT2
	2
r.   r   c                      e Zd ZdZdZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZddZ	ddZ
	 d	 	 	 	 	 dd	Z	 d	 	 	 	 	 	 	 dd
Zy)_GetMorezA getmore operation.)r!  r   rH  r   r   r  rL   r   r$  rS  r%  r&  r~   r   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        d | _
        || _        || _        y r   )r!  r   rH  r   r  rL   r   r$  r   rS  r%  r&  r~   )r  r!  r   rH  r   r  rL   r   r$  r   rS  r&  r~   s                rB   r  z_GetMore.__init__  sc     	""*.!2 AEr.   c                    d | _         y r   r)  r   s    rB   r*  z_GetMore.reset  r+  r.   c                8    | j                    d| j                   S r-  r.  r   s    rB   rI  z_GetMore.namespace  r/  r.   c                    d}| j                   sd}n|j                  dk\  rd}|j                  | j                  | j                         |S )NFTrc   )r&  r   r2  r$  r   )r  r   rG  s      rB   r4  z_GetMore.use_command  sC    ||G""a'Gdkk4<<8r.   c                *    || j                   f| _        y r   r6  r7  s     rB   r8  z_GetMore.update_command  r9  r.   c                
   | j                   | j                   S t        | j                  | j                  | j                  | j
                  | j                  |      }| j                  r(| j                  j                  |d| j                  |       |j                  |       |j                  || j                  | j                         |r|j                  | j                  d       || j                  f| _         | j                   S )z1Return a getMore command document for this query.NFr<  )r%  r   r   r   rH  r   r~   r   r>  rL   r=  r@  r$  rA  r!  )r  r   rA  r   s       rB   rB  z_GetMore.as_command  s    
 '###3NNIINN""LL
 <<LL""3t/C/CTJC sDLL$++>t{{5<r.   c                r   | j                         }|j                  }|rx| j                  |      d   }| j                  r| j                  rt
        j                  }nd}t        ||| j                  d| j                  |j                        \  }}	}
}||	|
fS t        || j                  | j                  |      S )zGet a getmore message.r   NrD  )rI  r  rB  rS  r&  r  r  r   r!  r  r	  rH  r   )r  dummy0r   rG  r  r   rK   r   r   r   r   r}  s               rB   rI  z_GetMore.get_message!  s     ^^&&??4(+D}}..'.tTWWdD,>,>DD\D\($JT1 sD((T^^T^^SAAr.   N)r!  rQ   r   rQ   rH  r5  r   r5  r  r   rL   r"   r   r6  r$  r*   r   r  rS  r   r&  r  r~   r   rL  rM  rN  rO  rP  rQ  )r]  r   r   r)   rG  r  r8  z0Union[tuple[int, bytes, int], tuple[int, bytes]])rS   r;  r<  r=  r>  r   r  r*  rI  r4  r8  rB  rI  rA   r.   rB   rU  rU    s    I  D  	
  $ % 2 % )   : (	( @E ' 8< 	# 6 GLBB!4B?CB	9Br.   rU  c                        e Zd Zd fdZ xZS )_RawBatchQueryc                ^    t         |   |       |j                  dk\  ry| j                  syyNrc   TFrD  r4  r   r&  r  r   rR   s     rB   r4  z_RawBatchQuery.use_command7  .    D!  A%r.   rN  rS   r;  r<  r4  rS  rT  s   @rB   r_  r_  6       r.   r_  c                        e Zd Zd fdZ xZS )_RawBatchGetMorec                ^    t         |   |       |j                  dk\  ry| j                  syyra  rb  rc  s     rB   r4  z_RawBatchGetMore.use_commandC  rd  r.   rN  re  rT  s   @rB   rh  rh  B  rf  r.   rh  c                  N    e Zd ZU dZded<   d
dZedd       ZddZddZ	ddZ
y	)_CursorAddresszEThe server address (host, port) of a cursor, with namespace property.r   _CursorAddress__namespacec                @    t         j                  | |      }||_        |S r   )tuple__new__rl  )r  r*  rI  r  s       rB   ro  z_CursorAddress.__new__S  s    }}S'*$r.   c                    | j                   S )zThe namespace this cursor.)rl  r   s    rB   rI  z_CursorAddress.namespaceX  s     r.   c                @    g | | j                   j                         S r   )rl  __hash__r   s    rB   rr  z_CursorAddress.__hash__]  s#     *$)(()3355r.   c                    t        |t              r2t        |       t        |      k(  xr | j                  |j                  k(  S t        S r   )rF  rk  rn  rI  NotImplementedr  others     rB   __eq__z_CursorAddress.__eq__b  s7    e^,;%,.T4>>U__3TTr.   c                    | |k(   S r   rA   ru  s     rB   __ne__z_CursorAddress.__ne__g  s    5=  r.   N)r*  r'   rI  rQ   r8  rk  rM  r7  )rv  objectr8  r  )rS   r;  r<  r=  __annotations__ro  r?  rI  rr  rw  ry  rA   r.   rB   rk  rk  N  s3    O
    6

!r.   rk  r7  )rK   rP  rL   r"   r8  rP  )rU   	Exceptionr8  r  )rl   rQ   rm   rJ  rn   rJ  r8  r  )NNN)r   rQ   rK   rJ  r   z1Optional[Union[Mapping[str, Any], Iterable[str]]]r   r5  r   r5  r   r  r   r  r   r&   r   r   r   r6  r   rK  r8  r  )r   r  r   rQ   r   r  r   r  r~   zOptional[Any]r   r)   r8  r  )rl   r5  r   r  r   .Union[SnappyContext, ZlibContext, ZstdContext]r8  tuple[int, bytes])rl   r5  r   r  r8  r~  )r   r5  rm   rJ  r   rQ   r   !Optional[list[Mapping[str, Any]]]r   r   r8  ztuple[bytes, int, int])r   r5  rm   rJ  r   rQ   r   r  r   r   r   r}  r8  tuple[int, bytes, int, int])r   r5  rm   rJ  r   rQ   r   r  r   r   r8  r  r   )r   r5  rm   rP  r   rQ   rL   zOptional[_ServerMode]r   r   r   4Union[SnappyContext, ZlibContext, ZstdContext, None]r8  r  )r   r5  r   rQ   r   r5  r   r5  r   rJ  r   r   r   r   r8  ztuple[bytes, int])r   r5  r   rQ   r   r5  r   r5  r   rJ  r   r   r   r   r   r}  r8  rR  )r   r5  r   rQ   r   r5  r   r5  r   rJ  r   r   r   r   r8  rR  )r   r5  r   rQ   r   r5  r   r5  r   rJ  r   r   r   r   r   r  r8  rR  )r   rQ   r   r5  r   r5  r8  r  )
r   rQ   r   r5  r   r5  r   r}  r8  r~  )r   rQ   r   r5  r   r5  r8  r~  )
r   rQ   r   r5  r   r5  r   r  r8  r~  )rl   rQ   r`  r5  ra  r5  r8  r   )rl   r5  rm   rJ  r   rQ  rn  r  r   r   r   rA  ro  r{  r8  #tuple[list[Mapping[str, Any]], int])rl   r5  rm   rJ  r   rQ  rn  r  r   r   r   rA  r8  %tuple[bytes, list[Mapping[str, Any]]])rl   r5  rm   rJ  r   rQ  rn  r  r   r   r   rA  r8  *tuple[int, bytes, list[Mapping[str, Any]]])rI  rQ   rl   r5  rm   rP  r   rQ  r   r   r   rA  r8  r  )r  r  r  r  r  r  rn  r  ro  r{  r8  r5  )rm   rJ  r  r  r  r  rn  r  r   r   r   r  ro  r{  r8  z<tuple[list[Mapping[str, Any]], list[Mapping[str, Any]], int])rm   rJ  r  r  r  r  rn  r  r   r   r   r  r8  z>tuple[bytes, list[Mapping[str, Any]], list[Mapping[str, Any]]])rm   rJ  r  r  r  r  rn  r  r   r   r   r  r8  Ctuple[int, bytes, list[Mapping[str, Any]], list[Mapping[str, Any]]])rm   rP  r  r  r  r  r   r   r   r  r8  r  )rI  rQ   rl   r5  rm   rP  r   rQ  r   r   r   rA  r8  r  )rI  rQ   rl   r5  rm   rP  r   rQ  r   r   r   rA  ro  r{  r8  r  )r=  
__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+   r@   r?   r  _INSERT_UPDATE_DELETE_EMPTYr  r  r  r   r  r  r  r   r;   r{  rC   rM   rV   rY   rr   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	  ri  r  rA  rV  rb  r^  ry  r~  r  r  rH  r  r  r  r  r  r  r  r  rY  r  r  r  r	  r  r  r   rU  r_  rh  rn  rk  rA   r.   rB   <module>r     s   #    "
 
 
  < <   & .!F	 	 	 ASS0  		  


	
..1// 	
 CO!*C  ? 
0

"5@$O
!!.!8I!!J  #"
2 .204%)0
0
0 B0 	0
 0 0 0 0 +0 .0 #0 0f
  %	
   & )6==499  +++&T++& v}}W%** FMM$$$	'&--.33 V]]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 !m8  Fs   S SS