
    _i#                       U d Z ddlmZ ddlZddlZddlmZm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mZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZm Z  ddl!m"Z" ddl#m$Z$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6 erddl7m8Z8 eefZ9de:d<   dZ;dZ<dZ=dZ>dZ?dZ@dZAdZBdZCdZDdZEdZFd ZGd!ZHd"ZId#ZJdZKd$ZLdZMd%e:d&<   dZNd%e:d'<   dZOd%e:d(<   d)ZPd*ZQd*ZRd+ZSd,e:d-<   d.ZTd,e:d/<   d0ZUd1ZVd2ZWd3gZXdd8ZYdd9ZZddd>Z[ej\        ej]        ej^        ej_        ej`        d?ZaddDZbddFZcddGZdddHZeddJZfddKZgddLZhddMZiddNZjddPZkddQZlddSZmddTZnddVZoddWZpddXZqddYZrddZZsdd]Ztdd^Zudd_Zvdd`ZwddcZx eyg dd          ZzddfZ{ddhZ|ddjZ}ddlZ~ddnZddpZddqZddrZddsZdduZddwZddyZdd|Zdd~Z eyg d          ZddZddZddZddZddZddgiZde:d<   i dedevde{deide$deqdebdeodebdendeodeddehdesdejdeudexi dejdebdebdebdepdeqdebdebdebdefdefdejdebdebdeldeede%eieeeredZde:d<   ebeeebeeefebeeweheoedZde:d<   e|e}ete+eejejeee~d
Zde:d<   ddiZde:d<   i Zde:d<   e                    e           e                                D ]\  ZZeD ]Zeevree         ee<   e                                Zde:d<   e                    e           g dZde:d<    eydg          ZddZ	 dddZddZ	 dddƄZddȄZddɄZ eyg dʢ          Z G d˄ d̦          Z G d̈́ deeef                   ZddτZdS )z9Functions and classes common to multiple pymongo modules.    )annotationsN)OrderedDictabc)get_close_matches)TYPE_CHECKINGAnyCallableIteratorMappingMutableMappingNoReturnOptionalSequenceTypeUnionoverload)unquote_plus)SON)UuidRepresentation)CodecOptionsDatetimeConversionTypeRegistry)RawBSONDocument)validate_compressorsvalidate_zlib_compression_level)
DriverInfo)ConfigurationError)_validate_event_listeners)ReadConcern)_MONGOS_MODES_ServerMode)	ServerApi)DEFAULT_WRITE_CONCERNWriteConcernvalidate_boolean)_AgnosticClientSessionzSequence[Type[Any]]ORDERED_TYPESi   i li z4.2      
         g      ?<   g      4@d      Optional[int]MAX_IDLE_TIME_MSMAX_IDLE_TIME_SECWAIT_QUEUE_TIMEOUT   T);   zSequence[int]COMMAND_NOT_FOUND_CODES)   i@  i@  UNAUTHORIZED_CODESi'  mongodbautoCANONICALIZE_HOST_NAMEnodestrreturntuple[str, int]c                    | }d}|                      d          }|dk    r$| d|         t          | |dz   d                   }}|                    d          r
|dd         }||fS )z5Split a host:port string into (host, int(port)) pair.ii  :Nr+   [)rfindint
startswith)r<   hostportidxs       1D:\Nbitz\venv\Lib\site-packages\pymongo/common.pypartition_noderK      st    DD
**S//C
byy$3$ZT#'))_!5!5ds AbDz:    c                R    t          |           \  }}|                                |fS )z6Split and normalize a node name from a hello response.)rK   lower)r<   rG   rH   s      rJ   
clean_noderO      s(    %%JD$ ::<<rL   keysuggestionsOptional[list[str]]r   c                h    d|  d}|r|dd                     |           dz  }t          |          )z1Raise ConfigurationError with the given key name.Unknown option: .z Did you mean one of (, z:) or maybe a camelCase version of one? Refer to docstring.)joinr   )rP   rQ   msgs      rJ   raise_config_errorrY      sK    
#S
#
#
#C {z		+(>(>zzzz
S
!
!!rL   )unspecifiedstandardpythonLegacy
javaLegacycsharpLegacyoptionvaluer   boolc                    t          |t                    r|dvrt          d|  d          |dk    S t          | |          S )z8Validates that value is True, False, 'true', or 'false'.)truefalseThe value of z must be 'true' or 'false'rc   )
isinstancer=   
ValueErrorr%   r_   r`   s     rJ   validate_boolean_or_stringri      sT    % )))OVOOOPPPFE***rL   rE   c                   t          |t                    r|S t          |t                    r2	 t          |          S # t          $ r t          d|  d          dw xY wt	          d|  dt          |                     )zDValidates that 'value' is an integer (or basestring representation).re   z must be an integerNWrong type for z , value must be an integer, not rf   rE   r=   rg   	TypeErrortyperh   s     rJ   validate_integerro      s    % T	E3		 T	Tu:: 	T 	T 	THVHHHIItS	T
[f[[dSXkk[[
\
\\s	   = Ac                X    t          | |          }|dk    rt          d|  d          |S )zFValidate that 'value' is a positive integer, which does not include 0.r   re   z must be a positive integerro   rg   r_   r`   vals      rJ   validate_positive_integerrt      s9    
65
)
)C
axxLLLLMMMJrL   c                X    t          | |          }|dk     rt          d|  d          |S )z1Validate that 'value' is a positive integer or 0.r   re   z must be a non negative integerrq   rr   s      rJ   validate_non_negative_integerrv      s9    
65
)
)C
QwwPPPPQQQJrL   Optional[str]c                p    ||S t          | |          }t          |                                           |S )z1Validates that 'value' is file-like and readable.)validate_stringopencloserh   s     rJ   validate_readabler|      s:    } FE**EKKLrL   c                *    ||S t          | |          S )z4Validate that 'value' is a positive integer or None.rt   rh   s     rJ   !validate_positive_integer_or_noner      s    }$VU333rL   c                *    ||S t          | |          S )z9Validate that 'value' is a positive integer or 0 or None.)rv   rh   s     rJ   %validate_non_negative_integer_or_noner      s    }(777rL   c                t    t          |t                    r|S t          d|  dt          |                     )z/Validates that 'value' is an instance of `str`.rk   z(, value must be an instance of str, not )rf   r=   rm   rn   rh   s     rJ   ry   ry      sB    % 
cfccVZ[`VaVacc
d
ddrL   c                *    ||S t          | |          S )z@Validates that 'value' is an instance of `basestring` or `None`.)ry   rh   s     rJ   validate_string_or_noner      s    }65)))rL   Union[int, str]c                    t          |t                    r|S t          |t                    r"	 t          |          S # t          $ r |cY S w xY wt	          d|  dt          |                     )/Validates that 'value' is an integer or string.rk   z,, value must be an integer or a string, not rl   rh   s     rJ   validate_int_or_basestringr     s    % 	E3		 	u:: 	 	 	LLL	
[&[[dSXkk[[  s   = AAc                   t          |t                    r|S t          |t                    r3	 t          |          }n# t          $ r |cY S w xY wt	          | |          S t          d|  dt          |                     )r   rk   z9, value must be an non negative integer or a string, not )rf   rE   r=   rg   rv   rm   rn   rr   s      rJ   'validate_non_negative_int_or_basestringr     s    % :	E3		 :	e**CC 	 	 	LLL	,VS999
h&hh[_`e[f[fhh  s   > AAfloatc                    |  d}	 t          |          }n7# t          $ r t          |          dt          $ r t          |          dw xY wd|cxk     rdk     sn t          |  d          |S )zXValidates that 'value' is a float, or can be converted to one, and is
    positive.
    z must be an integer or floatNr   g    eAz1 must be greater than 0 and less than one billion)r   rg   rm   )r_   r`   errmsgs      rJ   validate_positive_floatr   $  s     444F*e + + +  d* * * *T)*
 u????s????FUUUVVVLs	    4Ac                >    |dk    s|dk    rdS t          | |          S )zgValidates that 'value' is 0 or a positive float, or can be converted to
    0 or a positive float.
    r   0r   rh   s     rJ   validate_positive_float_or_zeror   7  s*     zzUc\\q"65111rL   Optional[float]c                0    ||S t          | |          dz  S zcValidates a timeout specified in milliseconds returning
    a value in floating point seconds.
    N     @@r   rh   s     rJ   validate_timeout_or_noner   @  s#     }"6511F::rL   c                l    |t          |  d          |dk    s|dk    rdS t          | |          dz  S )zValidates a timeout specified in milliseconds returning
    a value in floating point seconds for the case where None is an error
    and 0 is valid. Setting the timeout to nothing in the URI string is a
    config error.
    Nz cannot be Noner   r   r   )r   r   rh   s     rJ   validate_timeout_or_zeror   I  sK     } F!;!;!;<<<zzUc\\q"6511F::rL   c                H    ||dk    s|dk    rdS t          | |          dz  S )zValidates a timeout specified in milliseconds returning
    a value in floating point seconds. value=0 and value="0" are treated the
    same as value=None which means unlimited timeout.
    Nr   r   r   r   rh   s     rJ    validate_timeout_or_none_or_zeror   V  s3    
 }

esllt"6511F::rL   c                0    |dS t          | |          dz  S r   )r   rh   s     rJ   validate_timeoutmsr   `  s#     }t*6599FBBrL   c                >    |dk    s|dk    rdS t          | |          S )zBValidates maxStalenessSeconds according to the Max Staleness Spec.rB   z-1r~   rh   s     rJ   validate_max_stalenessr   i  s(    {{etmmr$VU333rL   dummyr!   c                T    t          |t                    st          |d          |S )zValidate a read preference.z is not a read preference)rf   r!   rm   r   r`   s     rJ   validate_read_preferencer   q  s0    e[)) ?5===>>>LrL   c                <    |t           vrt          | d          |S )zValidate read preference mode for a MongoClient.

    .. versionchanged:: 3.5
       Returns the original ``value`` instead of the validated read preference
       mode.
    z is not a valid read preference)r    rg   r   s     rJ   validate_read_preference_moder   x  s+     M!!EBBBCCCLrL   c                \    ddl m} ||vr!t          |  dt          |                     |S )z&Validate the authMechanism URI option.r   )
MECHANISMSz must be in )pymongo.auth_sharedr   rg   tuple)r_   r`   r   s      rJ   validate_auth_mechanismr     sH    ......JFCCj0A0ACCDDDLrL   c                    	 t           |         S # t          $ r( t          | dt          t                                dw xY w)z<Validate the uuid representation option selected in the URI.z3 is an invalid UUID representation. Must be one of N)_UUID_REPRESENTATIONSKeyErrorrg   r   r   s     rJ   validate_uuid_representationr     sg    $U++    . .*++. .
 
 		s	    2Anamelist[dict[str, str]]c                   t          |t                    s|g}g }|D ]}|dk    r|                    i            	 i }|                    d          D ]9}|                    d          \  }}t	          |          |t	          |          <   :|                    |           # t
          $ r t          |d|            dw xY w|S )z5Parse readPreferenceTags if passed as a client kwarg. ,rA   z not a valid value for N)rf   listappendsplitr   	Exceptionrg   )r   r`   tag_setstag_settagstagrP   rs   s           rJ   validate_read_preference_tagsr     s    eT"" %'H T Tb==OOB	TD}}S)) < <99S>>S*6s*;*;\#&&''OOD!!!! 	T 	T 	THH$HHIItS	TOs   A&B## C)SERVICE_NAMESERVICE_HOSTr;   SERVICE_REALMAWS_SESSION_TOKENENVIRONMENTTOKEN_RESOURCEdict[str, Union[bool, str]]c           	        i }t          |t                    s$t          |t                    st          dt	          |                     |                                D ]\  }}t          |t                    r|||<    t          |t                    r%t          |                                          ||<   Z|dv rt          |t                    r|||<   y|dv r;ddl	m
} t          ||          st          dt	          |                     |||<   t          d| dt	          |                     |S t          | |          }t          |          }|                    d	          D ]}|                    d
          \  }}}|st          d          |t          vr9d|v rt          d          t          | dt!          t                               |dk    rddlm}  ||          ||<   |||<   |S )z!Validate authMechanismProperties.zIAuth mechanism properties must be given as a string or a dictionary, not )ALLOWED_HOSTS)OIDC_CALLBACKOIDC_HUMAN_CALLBACKr   )OIDCCallbackz-callback must be an OIDCCallback object, not z)Invalid type for auth mechanism property rV   r   rA   z#Malformed auth mechanism propertiesr   zPauth mechanism properties must be key:value pairs like AWS_SESSION_TOKEN:<token>z< is not a supported auth mechanism property. Must be one of r;   ) _validate_canonicalize_host_name)rf   r=   dictrg   rn   itemsra   rN   r   pymongo.auth_oidc_sharedr   ry   r   r   	partition_MECHANISM_PROPSr   r   r   )	r_   r`   propsrP   r   opt_rs   r   s	            rJ   "validate_auth_mechanism_propertiesr     s   EeS!! %&& 	i\`af\g\gii    ++-- 	c 	cJC%%% c"c

E4(( c ZZ--//c

)))j.E.E)"c

@@@AAAAAA!%66 d$%bUYZ_U`U`%b%bccc"c

 !aS!a!aTXY^T_T_!a!abbbFE**EE{{3  mmC((Q 	DBCCC&&&"c)) E  
  - -)**- -   ***LLLLLL99#>>E#JJE#JJLrL   <Union[Type[MutableMapping[str, Any]], Type[RawBSONDocument]]c                   d}	 t          |t          j                  }n?# t          $ r2 t	          |d          rt          |j        t          j                  }Y nw xY w|s't          |t                    st          |  d          |S )z#Validate the document_class option.F
__origin__zg must be dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a subclass of collections.MutableMapping)
issubclassr   r   rm   hasattrr   r   )r_   r`   
is_mappings      rJ   validate_document_classr     s     JJs'9::

 J J J5,'' 	J#E$4c6HIIJJ  
j@@ 
 5 5 5
 
 	

 Ls    9AAOptional[TypeRegistry]c                f    |.t          |t                    st          |  dt                     |S )z"Validate the type_registry option.Nz must be an instance of )rf   r   rm   rh   s     rJ   validate_type_registryr     s8    E<!@!@6II<IIJJJLrL   	list[Any]c                r    t          |t                    s!t          |  dt          |                     |S )z!Validates that 'value' is a list.z must be a list, not )rf   r   rm   rn   rh   s     rJ   validate_listr     s<    eT"" G6EEUEEFFFLrL   Optional[list[Any]]c                *    ||S t          | |          S )z)Validates that 'value' is a list or None.)r   rh   s     rJ   validate_list_or_noner     s    }'''rL   Nonec                l    t          |t          j        t          f          st	          |  d          dS )z/Validates that 'value' is a list or a document.zu must either be a list or an instance of dict, bson.son.SON, or any other type that inherits from collections.MappingN)rf   r   r   r   rm   rh   s     rJ   validate_list_or_mappingr     sI    eck4011 
 " " "
 
 	

 
rL   c                ^    t          |t          j                  st          |  d          dS )z=Validate the type of method arguments that expect a document.zd must be an instance of dict, bson.son.SON, or any other type that inherits from collections.MappingN)rf   r   r   rm   rh   s     rJ   validate_is_mappingr   &  sD    eS[)) 
 " " "
 
 	

 
rL   c                l    t          |t          j        t          f          st	          |  d          dS )zEValidate the type of method arguments that expect a MongoDB document.z must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMappingN)rf   r   r   r   rm   rh   s     rJ   validate_is_document_typer   0  sJ    ec0/BCC 
 ) ) )
 
 	

 
rL   c                    ||S t          | |           t          |                    d                    dk    rt          |  d          |S )zValidate the appname option.Nzutf-8   z must be <= 128 bytes)ry   lenencoderg   rh   s     rJ   validate_appname_or_noner   ;  sW    }FE"""
5<<  !!C''F999:::LrL   Optional[DriverInfo]c                \    ||S t          |t                    st          |  d          |S ) Validate the driver keyword arg.Nz" must be an instance of DriverInfo)rf   r   rm   rh   s     rJ   validate_driver_or_noner   F  s;    }eZ(( G6EEEFFFLrL   Optional[ServerApi]c                z    ||S t          |t                    s!t          |  dt          |                     |S )z$Validate the server_api keyword arg.Nz' must be an instance of ServerApi, not )rf   r"   rm   rn   rh   s     rJ   validate_server_api_or_noner   O  sF    }eY'' Y6WW$u++WWXXXLrL   Optional[Callable[..., Any]]c                n    ||S t          |          s!t          |  dt          |                     |S )z%Validates that 'value' is a callable.Nz must be a callable, not )callablerg   rn   rh   s     rJ   validate_is_callable_or_noner   X  sB    }E?? LFJJT%[[JJKKKLrL   replacementMapping[str, Any]c                    t          d|            | rUt          | t                    sBt          t	          |                     }|                    d          rt          d          dS dS dS )z Validate a replacement document.r   $z'replacement can not include $ operatorsN)r   rf   r   nextiterrF   rg   )r   firsts     rJ   validate_ok_for_replacer  a  s    {333 H:k?CC HT+&&''C   	HFGGGH H H H	H 	HrL   updatec                    t          d|            | st          d          t          | t                     }t	          t          |                     }|r$|                    d          st          d          dS dS )zValidate an update document.r  zupdate cannot be emptyr   z"update only works with $ operatorsN)r   rg   rf   r   r   r   rF   )r  is_documentr   s      rJ   validate_ok_for_updater  k  s    Xv... 31222 ...KfE ?5++C00 ?=>>>? ? ? ?rL   )strictreplaceignorec                d    |t           vr&t          | dt          t                                |S )zAValidate the Unicode decode error handler option of CodecOptions.z< is an invalid Unicode decode error handler. Must be one of )_UNICODE_DECODE_ERROR_HANDLERSrg   r   r   s     rJ   %validate_unicode_decode_error_handlerr  {  sJ    222 7 73447 7
 
 	

 LrL   Optional[datetime.tzinfo]c                b    |,t          |t          j                  st          d|z            |S )zValidate the tzinfo optionNz)%s must be an instance of datetime.tzinfo)rf   datetimetzinform   r   s     rJ   validate_tzinfor    s2    E8?!C!CCeKLLLLrL   Optional[Any]c                |    ||S ddl m} t          ||          s!t          |  dt	          |                     |S )r   Nr   )AutoEncryptionOptsz0 must be an instance of AutoEncryptionOpts, not )pymongo.encryption_optionsr  rf   rm   rn   )r_   r`   r  s      rJ   %validate_auto_encryption_opts_or_noner    s]    }======e/00 b6``SWX]S^S^``aaaLrL   Optional[DatetimeConversion]c                L   |t           j        S t          |t                    r=|                                rt          t          |                    S t           |         S t          |t
                    rt          |          S t          |  dt          |                     )z%Validate a DatetimeConversion string.Nz; must be a str or int representing DatetimeConversion, not )r   DATETIMErf   r=   isdigitrE   rm   rn   rh   s     rJ   validate_datetime_conversionr    s    }!**% )==?? 	2%c%jj111!%((	E3		 )!%(((
[[dSXkk[[  rL   c                8    |dvrt          |  d|d          |S )z)Validate the serverMonitoringMode option.>   r:   pollstream=z7 is invalid. Must be one of "auto", "stream", or "poll")rg   rh   s     rJ   validate_server_monitoring_moder    s;    ...XXXXX
 
 	
 LrL   tlssslzdict[str, list[str]]URI_OPTIONS_ALIAS_MAPappnameauthmechanismauthmechanismproperties
authsourcecompressorsconnecttimeoutmsdirectconnectionheartbeatfrequencymsjournallocalthresholdmsmaxidletimemsmaxconnectingmaxpoolsizemaxstalenesssecondsreadconcernlevelreadpreferencereadpreferencetags
replicaset
retryreadsretrywritesloadbalancedserverselectiontimeoutmssockettimeoutmstlsallowinvalidcertificatestlsallowinvalidhostnames	tlscafiletlscertificatekeyfiletlscertificatekeyfilepasswordtlsdisableocspendpointchecktlsinsecurew
wtimeoutmszlibcompressionlevel)srvservicenamesrvmaxhosts	timeoutmsservermonitoringmode$dict[str, Callable[[Any, Any], Any]]URI_OPTIONS_VALIDATOR_MAP)connectdriver
server_apifsyncminpoolsize
tlscrlfiletz_awareunicode_decode_error_handleruuidrepresentationwaitqueuemultiplewaitqueuetimeoutmsdatetime_conversionNONSPEC_OPTIONS_VALIDATOR_MAP)
document_classtype_registryread_preferenceevent_listenersr  usernamepasswordserver_selectorauto_encryption_optsauthoidcallowedhostsKW_VALIDATORSzdict[str, str]INTERNAL_URI_OPTION_NAME_MAPzdict[str, tuple[str, str]]URI_OPTIONS_DEPRECATION_MAP
VALIDATORS)r(  r*  r-  r0  r8  r9  rT  z	list[str]TIMEOUT_OPTIONStuple[str, Any]c                v    t          | |          \  }}|t          vrt          d|  dt                     | |fS )z,Validate optional authentication parameters.rT   z. Must be in )validate_AUTH_OPTIONSr   )r_   r`   rN   s      rJ   validate_auth_optionri  6  sI    FE**LE5M!! !XF!X!X!X!XYYY5=rL   
validators
normed_keyCallable[[Any, Any], Any]c                    |p| }	 ||         S # t           $ r& t          ||d          }t          | |           Y d S w xY w)Ng?)cutoff)r   r   rY   )rP   rj  rk  rQ   s       rJ   _get_validatorro  >  sf     "sJ-*%% - - -'
JsKKK3,,,,,,-s    ,>>c                t    t          | t          |                                           } || |          }| |fS )zGeneric validation function.rk  )ro  rc  rN   )r_   r`   	validators      rJ   rg  rg  I  s9    vzfllnnMMMIIfe$$E5=rL   optionswarnMutableMapping[str, Any]c                .   
 t           t                    rt                      }dd}d fd}n
i }dd}dd}                                 D ]\  }} ||          }	 t          |t          |          } |||          }	|	| ||          <   C# t
          t          t          f$ ri
|d	k    r2t          
fd
t          D                       rdt          
          vr |r$t          j        t          
          d           n Y d

d

ww xY w|S )aa  Validate each entry in options and raise a warning if it is not valid.
    Returns a copy of options with invalid entries removed.

    :param opts: A dict containing MongoDB URI options.
    :param warn: If ``True`` then warnings will be logged and
          invalid options will be ignored. Otherwise, invalid options will
          cause errors.
    xr=   r>   c                    | S N rw  s    rJ   get_normed_keyz-get_validated_options.<locals>.get_normed_key_      HrL   c                .                         |           S ry  )	cased_key)rw  rs  s    rJ   get_setter_keyz-get_validated_options.<locals>.get_setter_keyb  s    $$Q'''rL   c                *    |                                  S ry  )rN   r{  s    rJ   r|  z-get_validated_options.<locals>.get_normed_keyh  s    7799rL   c                    | S ry  rz  r{  s    rJ   r  z-get_validated_options.<locals>.get_setter_keyk  r}  rL   rq  r%  c              3  :   K   | ]}|t                    v V  d S ry  r=   ).0pexcs     rJ   	<genexpr>z(get_validated_options.<locals>.<genexpr>v  s-      EE!SXXEEEEEErL   z*is not a supported auth mechanism propertyr/   )
stacklevelN)rw  r=   r>   r=   )rf   _CaseInsensitiveDictionaryr   ro  rI  rg   rm   r   any_MECH_PROP_MUST_RAISEr=   warningsrt  )rs  rt  validated_optionsr|  r  r   r`   rk  rr  	validatedr  s   `         @rJ   get_validated_optionsr  P  s    '566 688	 	 	 		( 	( 	( 	( 	( 	( 	( 	 	 	 		 	 	 	 mmoo F F
U#^C((
	F&s,ER\]]]I!	#u--I =FnnZ8899 I'9: 
	 
	 
	777EEEE/DEEEEE 8@CPP c#hh155555 65555
	 s    #BD)ADDencrypted_fieldsc                6    |                      dd| d          S )NescCollectionenxcol_.z.escgetr  r   s     rJ   _esc_coll_namer    s$    1FD1F1F1FGGGrL   c                6    |                      dd| d          S )NecocCollectionr  z.ecocr  r  s     rJ   _ecoc_coll_namer    s%     02HT2H2H2HIIIrL   )rA  wtimeoutrB  rM  jr+  c                      e Zd ZdZddZedd            Zedd            ZddZedd            Z	ddZ
edd            ZdS )
BaseObjectzA base class that provides attributes and methods common
    to multiple pymongo classes.

    SHOULD NOT BE USED BY DEVELOPERS EXTERNAL TO MONGODB.
    codec_optionsCodecOptions[Any]rY  r!   write_concernr$   read_concernr   r>   r   c                   t          |t                    st          d          || _        t          |t                    st          |d          || _        t          |t                    st          dt          |                     || _        t          |t                    st          dt          |                     || _
        d S )NzDcodec_options must be an instance of bson.codec_options.CodecOptionszR is not valid for read_preference. See pymongo.read_preferences for valid options.zMwrite_concern must be an instance of pymongo.write_concern.WriteConcern, not zJread_concern must be an instance of pymongo.read_concern.ReadConcern, not )rf   r   rm   _codec_optionsr!   _read_preferencer$   rn   _write_concernr   _read_concern)selfr  rY  r  r  s        rJ   __init__zBaseObject.__init__  s     -66 	dbccc+/;77 	"     
 !0-66 	u`der`s`suu   ,,44 	q]abn]o]oqq   *rL   c                    | j         S )zdRead only access to the :class:`~bson.codec_options.CodecOptions`
        of this instance.
        )r  r  s    rJ   r  zBaseObject.codec_options  s    
 ""rL   c                    | j         S )zRead only access to the :class:`~pymongo.write_concern.WriteConcern`
        of this instance.

        .. versionchanged:: 3.0
          The :attr:`write_concern` attribute is now read only.
        )r  r  s    rJ   r  zBaseObject.write_concern  s     ""rL   session Optional[_AgnosticClientSession]c                0    |r|j         rt          S | j        S )zBRead only access to the write concern of this instance or session.)in_transactionr#   r  r  r  s     rJ   _write_concern_forzBaseObject._write_concern_for  s%      	)w- 	)((!!rL   c                    | j         S )zRead only access to the read preference of this instance.

        .. versionchanged:: 3.0
          The :attr:`read_preference` attribute is now read only.
        )r  r  s    rJ   rY  zBaseObject.read_preference  s     $$rL   c                J    |r|                                 p| j        S | j        S )zDRead only access to the read preference of this instance or session.)_txn_read_preferencer  r  s     rJ   _read_preference_forzBaseObject._read_preference_for  s0      	K//11JT5JJ$$rL   c                    | j         S )zRead only access to the :class:`~pymongo.read_concern.ReadConcern`
        of this instance.

        .. versionadded:: 3.2
        )r  r  s    rJ   r  zBaseObject.read_concern  s     !!rL   N)
r  r  rY  r!   r  r$   r  r   r>   r   )r>   r  )r>   r$   )r  r  r>   r$   )r>   r!   )r  r  r>   r!   )r>   r   )__name__
__module____qualname____doc__r  propertyr  r  r  rY  r  r  rz  rL   rJ   r  r    s         * * * *> # # # X# # # # X#" " " " % % % X%% % % % " " " X" " "rL   r  c                      e Zd Zd$dZd%d	Zd&dZd'dZd(dZd)dZd*dZ	d+dZ
d,dZd-d.dZd/dZd0dZd1dZed-d2d            Zed3d            Zd-d4d Zd5d"Zd*d#ZdS )6r  argsr   kwargsc                `    i | _         i | _        |                     t          |i |           d S ry  )%_CaseInsensitiveDictionary__casedkeys _CaseInsensitiveDictionary__datar  r   )r  r  r  s      rJ   r  z#_CaseInsensitiveDictionary.__init__  s6    +-&(D$)&))*****rL   rP   r=   r>   ra   c                8    |                                 | j        v S ry  )rN   r  r  rP   s     rJ   __contains__z'_CaseInsensitiveDictionary.__contains__  s    yy{{dk))rL   rE   c                *    t          | j                  S ry  )r   r  r  s    rJ   __len__z"_CaseInsensitiveDictionary.__len__  s    4;rL   Iterator[str]c                $    d | j         D             S )Nc              3     K   | ]}|V  d S ry  rz  )r  rP   s     rJ   r  z6_CaseInsensitiveDictionary.__iter__.<locals>.<genexpr>  s"      00000000rL   )r  r  s    rJ   __iter__z#_CaseInsensitiveDictionary.__iter__  s    00t/0000rL   c                :     t           fd D                       S )Nc                B    i | ]}j         |         j        |         S rz  )r  r  )r  kr  s     rJ   
<dictcomp>z7_CaseInsensitiveDictionary.__repr__.<locals>.<dictcomp>  s)    FFFAD$Q'QFFFrL   r  r  s   `rJ   __repr__z#_CaseInsensitiveDictionary.__repr__  s&    FFFFFFFGGGrL   r`   r   c                V    |                                 }|| j        |<   || j        |<   d S ry  rN   r  r  )r  rP   r`   lc_keys       rJ   __setitem__z&_CaseInsensitiveDictionary.__setitem__  s.    #& #FrL   c                @    | j         |                                         S ry  )r  rN   r  s     rJ   __getitem__z&_CaseInsensitiveDictionary.__getitem__  s    {399;;''rL   c                N    |                                 }| j        |= | j        |= d S ry  r  )r  rP   r  s      rJ   __delitem__z&_CaseInsensitiveDictionary.__delitem__  s*    V$KrL   otherc                    t          |t          j                  st          S t	          |           t	          |          k    rdS |D ]}| |         ||         k    r dS dS )NFT)rf   r   r   NotImplementedr   r  r  rP   s      rJ   __eq__z!_CaseInsensitiveDictionary.__eq__  sm    %-- 	"!!t99E

""5 	 	CCyE#J&&uu ' trL   Ndefaultr  c                \    | j                             |                                |          S ry  )r  r  rN   r  rP   r  s      rJ   r  z_CaseInsensitiveDictionary.get  s     {syy{{G444rL   c                    |                                 }| j                            |d             | j        j        |g|R i |S ry  )rN   r  popr  )r  rP   r  r  r  s        rJ   r  z_CaseInsensitiveDictionary.pop  sL    VT***t{v7777777rL   re  c                v    | j                                         \  }}| j                            |          }||fS ry  )r  popitemr  r  )r  r  r  r`   s       rJ   r  z"_CaseInsensitiveDictionary.popitem  s9     ,4466	''%rL   c                j    | j                                          | j                                         d S ry  )r  clearr  r  s    rJ   r  z _CaseInsensitiveDictionary.clear  s1       rL   c                    d S ry  rz  r  s      rJ   
setdefaultz%_CaseInsensitiveDictionary.setdefault"      rL   c                    d S ry  rz  r  s      rJ   r  z%_CaseInsensitiveDictionary.setdefault&  r  rL   c                x    |                                 }|| v r| j        |         S || j        |<   || j        |<   |S ry  )rN   r  r  )r  rP   r  r  s       rJ   r  z%_CaseInsensitiveDictionary.setdefault*  sC    $;;;v&&'*DV$")DKNrL   r   c                    t          |t                    r%|D ] }||         | |                    |          <   !d S |D ]}||         | |<   d S ry  )rf   r  r  r  s      rJ   r  z!_CaseInsensitiveDictionary.update3  su    e788 	' 8 8-23ZU__S))**8 8  ' '!#JS		' 'rL   c                @    | j         |                                         S ry  )r  rN   r  s     rJ   r  z$_CaseInsensitiveDictionary.cased_key;  s    		,,rL   )r  r   r  r   )rP   r=   r>   ra   )r>   rE   )r>   r  )r>   r=   )rP   r=   r`   r   r>   r   )rP   r=   r>   r   )rP   r=   r>   r   )r  r   r>   ra   ry  )rP   r=   r  r  r>   r   )rP   r=   r  r   r  r   r>   r   )r>   re  )r>   r   )rP   r=   r  r   r>   r  )rP   r=   r  r   r>   r   )rP   r=   r  r  r>   r  )r  r   r>   r   )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  rz  rL   rJ   r  r    s       + + + +
* * * *       1 1 1 1H H H H$ $ $ $
( ( ( (       
	 	 	 	5 5 5 5 58 8 8 8
       
        X    X    ' ' ' '- - - - - -rL   r  c                 6    	 ddl m}  dS # t          $ r Y dS w xY w)zIs the C extension installed?r   	_cmessageTF)pymongor  ImportErrorr  s    rJ   has_cr  ?  s@    %%%%%%t   uus   
 
)r<   r=   r>   r?   ry  )rP   r=   rQ   rR   r>   r   )r_   r=   r`   r   r>   ra   )r_   r=   r`   r   r>   rE   )r_   r=   r`   r   r>   rw   )r_   r=   r`   r   r>   r0   )r_   r=   r`   r   r>   r=   )r_   r=   r`   r   r>   r   )r_   r   r`   r   r>   r   )r_   r=   r`   r   r>   r   )r_   r=   r`   r   r>   r   )r_   r   r`   r   r>   r   )r   r   r`   r   r>   r!   )r   r   r`   r   r>   rE   )r   r=   r`   r   r>   r   )r_   r=   r`   r   r>   r   )r_   r=   r`   r   r>   r   )r_   r   r`   r   r>   r   )r_   r=   r`   r   r>   r   )r_   r   r`   r   r>   r   )r_   r   r`   r   r>   r   )r_   r=   r`   r   r>   r   )r_   r   r`   r   r>   r   )r_   r   r`   r   r>   r   )r_   r   r`   r   r>   r   )r   r   r>   r   )r  r   r>   r   )r   r   r`   r=   r>   r=   )r   r   r`   r   r>   r  )r_   r   r`   r   r>   r  )r_   r   r`   r   r>   r  )r_   r=   r`   r=   r>   r=   )r_   r=   r`   r   r>   re  )rP   r=   rj  rH  rk  rw   r>   rl  )T)rs  r   rt  ra   r>   ru  )r  r   r   r=   r>   r   )r>   ra   )r  
__future__r   r  r  collectionsr   r   difflibr   typingr   r   r	   r
   r   r   r   r   r   r   r   r   urllib.parser   bsonr   bson.binaryr   bson.codec_optionsr   r   r   bson.raw_bsonr   pymongo.compression_supportr   r   pymongo.driver_infor   pymongo.errorsr   pymongo.monitoringr   pymongo.read_concernr   pymongo.read_preferencesr    r!   pymongo.server_apir"   pymongo.write_concernr#   r$   r%   pymongo.typingsr&   r'   __annotations__MAX_BSON_SIZEMAX_MESSAGE_SIZEMIN_WIRE_VERSIONMAX_WIRE_VERSIONMAX_WRITE_BATCH_SIZEMIN_SUPPORTED_SERVER_VERSIONMIN_SUPPORTED_WIRE_VERSIONMAX_SUPPORTED_WIRE_VERSIONHEARTBEAT_FREQUENCYKILL_CURSOR_FREQUENCYEVENTS_QUEUE_FREQUENCYSERVER_SELECTION_TIMEOUTMIN_HEARTBEAT_INTERVALMIN_SRV_RESCAN_INTERVALCONNECT_TIMEOUTMAX_POOL_SIZEMIN_POOL_SIZEMAX_CONNECTINGr1   r2   r3   LOCAL_THRESHOLD_MSRETRY_WRITESRETRY_READSr6   r8   _MAX_END_SESSIONSSRV_SERVICE_NAMESERVER_MONITORING_MODEr  rK   rO   rY   UNSPECIFIEDSTANDARDPYTHON_LEGACYJAVA_LEGACYCSHARP_LEGACYr   ri   ro   rt   rv   r|   r   r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	frozensetr   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r  r"  rI  rV  r`  ra  rb  r  r   optnamealiasesaliascopyrc  rd  rh  ri  ro  rg  r  r  r  WRITE_CONCERN_OPTIONSr  r=   r  r  rz  rL   rJ   <module>r+     s    @ ? ? " " " " " "   ( ( ( ( ( ( ( ( % % % % % %                            & % % % % %       * * * * * * M M M M M M M M M M ) ) ) ) ) )        + * * * * * - - - - - - 8 8 8 8 8 8 , , , , , , ? ? ? ? ? ? ? ? ( ( ( ( ( ( W W W W W W W W W W 7666666 '*;%7 7 7 7 7 #      %                    #'  & & & & $(  ' ' ' ' %)  ( ( ( (     */  . . . . %7  6 6 6 6        22 	 	 	 	   " " " " " &1"+&4$0&4  + + + +	] 	] 	] 	]         4 4 4 48 8 8 8e e e e* * * *         &2 2 2 2; ; ; ;
; 
; 
; 
;; ; ; ;C C C C4 4 4 4   	 	 	 	   	 	 	 	   * 9  
 
 4 4 4 4n   *      ( ( ( (
 
 
 

 
 
 

 
 
 
            H H H H
? 
? 
? 
? "++J+J+J!K!K       	 	 	 	   "    
E7/     'C''C,'C A'C /	'C
 ''C 8'C 2'C 4'C )'C 7'C -'C .'C 8'C 1'C /'C  3!'C" 7#'C 'C$ )%'C& ,''C( -)'C* .+'C,  8-'C. 7/'C0 
%1'C2 "#=3'C4  :5'C6 "7'C8 .9'C: $%<;'C< "#=='C> -?'C@ 	0A'CB /C'CD ;E'C 'CF &0#;M'C 'C 'C  ' ' ' 'X *%-'0#*$I6>27G G     & .+/0''3A)7 7    $ 
50     	;  	 	 	 	     !> ? ? ?-3355 R RGW R R111/H/Q%e,R
 4M3Q3Q3S3S
 S S S S 
  -             	4566    ]a- - - - -    .20 0 0 0 0fH H H HJ J J J
 "	"Z"Z"Z[[ U" U" U" U" U" U" U" U"pU- U- U- U- U-S!9 U- U- U-p     rL   