
    &g+                       % S r SSKJ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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Jr  \(       a  SS	KJ r   SS
K!J"r"  SSK#J$r$  \%" SS/5      r&S\'S'   \%" / SQ5      \&-  r(S\'S'   \(\%" / SQ5      -  r)S\'S'   Sr*S\'S'   Sr+S\'S'   1 Skr,S\'S'   S'S jr- S(     S)S jjr.S*S jr/S+S jr0  S,         S-S  jjr1S.S! jr2S/S" jr3S0S# jr4S1S$ jr5      S2S% jr6S3S& jr7g)4zCBits and pieces used by the driver that don't really fit elsewhere.    )annotationsN)abc)	TYPE_CHECKINGAny	ContainerIterableMappingNoReturnOptionalSequenceUnion)	ASCENDING)	CursorNotFoundDuplicateKeyErrorExecutionTimeoutNotPrimaryErrorOperationFailureWriteConcernError
WriteErrorWTimeoutError_wtimeout_error)HelloCompat)_Hint)
_IndexList)_DocumentOutiP-  [   	frozenset_SHUTDOWN_CODES)iJ'  i{'  i{4  iR-  i|4     _NOT_PRIMARY_CODES)      Y   i)#  i     _RETRYABLE_ERROR_CODESi  int_REAUTHENTICATION_REQUIRED_CODE   _AUTHENTICATION_FAILURE_CODE>	   copydbgetnonce	saslstart
createuser
updateuserauthenticatesaslcontinuecopydbgetnoncecopydbsaslstartset_SENSITIVE_COMMANDSc                j    SR                  U  Vs/ s H  nSR                  " U6 PM     sn5      $ s  snf )z9Generate an index name from the set of fields it is over._z{}_{})joinformat)keysitems     [C:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\pymongo/helpers_shared.py_gen_index_namer<   o   s,    88t<ttW^^T*t<==<s   0c                B   Ub0  [        U [        5      (       d  [        S[        U 5       35      eX4/$ [        U [        5      (       a	  U [        4/$ [        U [
        R                  5      (       a  [        U 5      $ [        U [
        R                  5      (       a  [        U R                  5       5      $ [        U [        [        45      (       d  [        S[        U 5       35      e/ nU  H1  n[        U[        5      (       a  U[        4nUR                  U5        M3     U$ )zyHelper to generate a list of (key, direction) pairs.

Takes such a list, or a single key, or a single key and direction.
z'Expected a string and a direction, not zKif no direction is specified, key_or_list must be an instance of list, not )
isinstancestr	TypeErrortyper   r   	ItemsViewlistr	   itemstupleappend)key_or_list	directionvaluesr:   s       r;   _index_listrJ   t   s    +s++Ed;FWEXYZZ())k3'' ),--S]]33$$S[[11))+,,K$77]^bcn^o]pq  )+D$$$i(MM$       c                   [        U [        [        [        R                  45      (       d  [        S[        U 5      -   5      e[        U 5      (       d  [        S5      e0 n[        U [        R                  5      (       a  U  H  nX   n[        X#5        X1U'   M     U$ U  H3  n[        U[        5      (       a  U[        4nUu  p#[        X#5        X1U'   M5     U$ )zZHelper to generate an index specifying document.

Takes a list of (key, direction) pairs.
z@must use a dictionary or a list of (key, direction) pairs, not: zkey_or_list must not be empty)r>   rC   rE   r   r	   r@   reprlen
ValueError_validate_index_key_pairr?   r   )
index_listindexkeyvaluer:   s        r;   _index_documentrU      s    
 j4"<==NQUV`Qaa
 	
 z??899E*ckk**COE$S0#J  L D$$$i(JC$S0#J  LrK   c                    [        U [        5      (       d  [        S[        U 5       35      e[        U[        [        [
        R                  45      (       d  [        S[        U5       35      eg )Nz<first item in each key pair must be an instance of str, not zasecond item in each key pair must be 1, -1, '2d', or another valid MongoDB index specifier., not )r>   r?   r@   rA   r&   r   r	   )rS   rT   s     r;   rP   rP      sg    c3VW[\_W`Vabccec3455%[M#
 	
 6rK   c                   SU ;  a,  [        U R                  S5      U R                  S5      U U5      eU(       aA  SU ;   a;  U S   nU R                  S5      nU(       a  UR                  SU05        [        U5        U S   (       a  gU nSU ;   aL  U S   R	                  5        H5  nUR                  S5      (       d  M  UR                  S5      (       a  M3  Un  O   US   nUR                  S5      n	U(       a  U	b  X;   a  gOX;   a  gU	b  U	[
        ;   a  [        X5      eO%[        R                  U;   d  S	U;   a  [        X5      eU	S
;   a  [        XX5      eU	S:X  a  [        XX5      eU	S:X  a  [        XX5      e[        XX5      e)z+Check the response to a command for errors.okz$errcodewriteConcernErrorerrorLabelsNrawerrmsgznode is recovering)*  i*  i&1  2   +   )r   getupdate_raise_write_concern_errorrI   r    r   r   LEGACY_ERRORr   r   r   )
responsemax_wire_versionallowable_errorsparse_write_concern_error_error_labelsdetailsshardr]   rY   s
             r;   _check_command_responserm      s    8LL LL 	
 	
 !%8H%D-.,,}-MM='23"6*~G e_++-Eyy""599T??	 . XF;;vD ' (' %%!&33 &		!	!V	+/Cv/Mf// $$hII	vXHH	V8FF
6
DDrK   c                    U S   nUR                  S5      S:X  a  [        UR                  S5      SU5      e[        UR                  S5      UR                  S5      U5      e)NrY   r^   r]   )ra   r   r   )write_errorserrors     r;   _raise_last_write_errorrr      sX     EyyE!		( 3UEBB
UYYx(%))F*;U
CCrK   c                    [        U 5      (       a+  [        U R                  S5      U R                  S5      U 5      e[        U R                  S5      U R                  S5      U 5      e)Nr]   rY   )r   r   ra   r   )rq   s    r;   rc   rc     sO    uEIIh/61BEJJ
EIIh/61BE
JJrK   c                    U R                  S5      nU(       a,  U R                  S5      nU(       a  UR                  5       nX!S'   U$ )z%Return the writeConcernError or None.rZ   r[   )ra   copy)resultwceerror_labelss      r;   _get_wce_docry     s?    
**(
)C
 zz-0((*C!-JrK   c                    U R                  S5      nU(       a  [        U5        [        U 5      nU(       a  [        U5        gg)z?Backward compatibility helper for write command error handling.writeErrorsN)ra   rr   ry   rc   )rv   rp   rw   s      r;   _check_write_command_responser|     s7     ::m,L-
v
C
"3' rK   c                4   [        U [        R                  5      (       a  U $ [        U [        R                  [        R                  45      (       a;  [        S U  5       5      (       d  [        U S35      e[        R                  U S5      $ [        U S35      e)zTakes a sequence of field names and returns a matching dictionary.

["a", "b"] becomes {"a": 1, "b": 1}

and

["a.b.c", "d", "a.c"] becomes {"a.b.c": 1, "d": 1, "a.c": 1}
c              3  B   #    U  H  n[        U[        5      v   M     g 7fN)r>   r?   ).0fields     r;   	<genexpr>'_fields_list_to_dict.<locals>.<genexpr>6  s     >ve:eS))vs   z5 must be a list of key names, each an instance of str   z' must be a mapping or list of key names)	r>   r   r	   r   Setallr@   dictfromkeys)fieldsoption_names     r;   _fields_list_to_dictr   '  s|     &#++&&&3<<122>v>>>{m+`abb}}VQ''
{m#JK
LLrK   c                     [         R                  (       aI  [         R                  " 5       n  [        R                  " U S   U S   U S   S[         R                  5        A gg! [
         a     Nf = f! A f = f)z1Print exceptions raised by subscribers to stderr.r   r      N)sysstderrexc_info	tracebackprint_exceptionOSError)einfos    r;   _handle_exceptionr   =  se     zz	%%eAha%(D#**U    		 s#   1A   
A-*A0 ,A--A0 0A3)r9   r   returnr?   r   )rG   r   rH   zOptional[Union[int, str]]r   z8Sequence[tuple[str, Union[int, str, Mapping[str, Any]]]])rQ   r   r   zdict[str, Any])rS   r   rT   r   r   None)NF)
re   r   rf   zOptional[int]rg   z$Optional[Container[Union[int, str]]]rh   boolr   r   )rp   z	list[Any]r   r
   )rq   r   r   r
   )rv   Mapping[str, Any]r   zOptional[Mapping[str, Any]])rv   r   r   r   )r   z'Union[Mapping[str, Any], Iterable[str]]r   r?   r   r   )r   r   )8__doc__
__future__r   r   r   collectionsr   typingr   r   r   r   r	   r
   r   r   r   pymongor   pymongo.errorsr   r   r   r   r   r   r   r   r   pymongo.hellor   pymongo.cursor_sharedr   pymongo.operationsr   pymongo.typingsr   r   r   __annotations__r    r%   r'   r)   r4   r<   rJ   rU   rP   rm   rr   rc   ry   r|   r   r    rK   r;   <module>r      s   J " 
  
 
 
 
 
 
 &+-,
 '
  	
	 
 I  %7	: 	% 	 	 (+  * %' c &

 S 
> @D#<=<:
 >B&+	@E@E#@E ;@E  $	@E
 
@EFDK	(M3MBEMM,rK   