o
    h                     @  s  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rd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ZXdd8d9ZYdd:d;ZZddd@dAZ[ej\ej]ej^ej_ej`dBZaddGdHZbddJdKZcddLdMZdddNdOZeddQdRZfd	dSdTZgd	dUdVZhd
dWdXZiddYdZZjdd\d]Zkdd^d_ZlddadbZmddcddZnddfdgZoddhdiZpddjdkZqddldmZrddndoZsddrdsZtddtduZud
dvdwZvddxdyZwdd|d}Zxeyg d~ZzdddZ{dddZ|dddZ}dddZ~dddZdddZdddZdddZdddZdddZdddZdddZdddZdddZeyg dZdddZd ddZd!ddZd"ddZd#dd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< ee e D ]\ZZeD ]Zeevree ee< qސqe Zde:d< ee g dZde:d< eydgZd$ddZ	dd%ddZd$ddZ	*d&d'ddZd(ddZd(ddZeyg dZG dd dZG dd  d eeef Zd)dd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]ORDERED_TYPESi   i li z4.0      
         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'  ZmongodbautoCANONICALIZE_HOST_NAMEnodestrreturntuple[str, int]c                 C  sZ   | }d}|  d}|dkr| d| t| |d 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idx rG   A/var/www/html/venv/lib/python3.10/site-packages/pymongo/common.pypartition_node   s   
"
rI   c                 C  s   t | \}}| |fS )z6Split and normalize a node name from a hello response.)rI   lower)r:   rD   rE   rG   rG   rH   
clean_node   s   rK   keysuggestionsOptional[list]r   c                 C  s.   d|  d}|r|dd | d7 }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   )rL   rM   msgrG   rG   rH   raise_config_error   s   rT   )unspecifiedstandardZpythonLegacyZ
javaLegacyZcsharpLegacyoptionvaluer   boolc                 C  s4   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'rZ   )
isinstancer;   
ValueErrorr$   rW   rX   rG   rG   rH   validate_boolean_or_string   s
   

r`   rB   c                 C  s\   t |tr|S t |tr"zt|W S  ty!   td|  ddw td|  dt| )zDValidates that 'value' is an integer (or basestring representation).r\   z must be an integerNWrong type for z , value must be an integer, not r]   rB   r;   r^   	TypeErrortyper_   rG   rG   rH   validate_integer   s   


re   c                 C  s&   t | |}|dkrtd|  d|S )zFValidate that 'value' is a positive integer, which does not include 0.r   r\   z must be a positive integerre   r^   rW   rX   valrG   rG   rH   validate_positive_integer      
ri   c                 C  s&   t | |}|dk rtd|  d|S )z1Validate that 'value' is a positive integer or 0.r   r\   z must be a non negative integerrf   rg   rG   rG   rH   validate_non_negative_integer   rj   rk   Optional[str]c                 C  s&   |du r|S t | |}t|  |S )z1Validates that 'value' is file-like and readable.N)validate_stringopencloser_   rG   rG   rH   validate_readable   s
   
rp   c                 C     |du r|S t | |S )z4Validate that 'value' is a positive integer or None.Nri   r_   rG   rG   rH   !validate_positive_integer_or_none      
rs   c                 C  rq   )z9Validate that 'value' is a positive integer or 0 or None.N)rk   r_   rG   rG   rH   %validate_non_negative_integer_or_none   rt   ru   c                 C  s&   t |tr|S td|  dt| )z/Validates that 'value' is an instance of `str`.ra   z(, value must be an instance of str, not )r]   r;   rc   rd   r_   rG   rG   rH   rm      s   
rm   c                 C  rq   )z@Validates that 'value' is an instance of `basestring` or `None`.N)rm   r_   rG   rG   rH   validate_string_or_none   rt   rv   Union[int, str]c                 C  sR   t |tr|S t |trzt|W S  ty   | Y S w td|  dt| )/Validates that 'value' is an integer or string.ra   z,, value must be an integer or a string, not rb   r_   rG   rG   rH   validate_int_or_basestring  s   


ry   c                 C  s^   t |tr|S t |tr#zt|}W n ty   | Y S w t| |S td|  dt| )rx   ra   z9, value must be an non negative integer or a string, not )r]   rB   r;   r^   rk   rc   rd   rg   rG   rG   rH   'validate_non_negative_int_or_basestring  s   


rz   floatc                 C  sn   |  d}zt |}W n ty   t|d ty"   t|dw d|  k r-dk s5n 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{   r^   rc   )rW   rX   errmsgrG   rG   rH   validate_positive_float$  s   


r}   c                 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}   r_   rG   rG   rH   validate_positive_float_or_zero7  s   
r   Optional[float]c                 C  s   |du r|S t | |d S zcValidates a timeout specified in milliseconds returning
    a value in floating point seconds.
    N     @@r   r_   rG   rG   rH   validate_timeout_or_none@     r   c                 C  s8   |du rt |  d|dks|dkrdS t| |d 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}   r_   rG   rG   rH   validate_timeout_or_zeroI  s
   r   c                 C  s*   |du s|dks|dkrdS t | |d 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   r_   rG   rG   rH    validate_timeout_or_none_or_zeroV  s   r   c                 C  s   |du rdS t | |d S r   )r   r_   rG   rG   rH   validate_timeoutms`  r   r   c                 C  r~   )zBValidates maxStalenessSeconds according to the Max Staleness Spec.r?   z-1rr   r_   rG   rG   rH   validate_max_stalenessi  s   
r   dummyr    c                 C  s   t |tst|d|S )zValidate a read preference.z is not a read preference)r]   r    rc   r   rX   rG   rG   rH   validate_read_preferenceq  s   
r   c                 C  s   |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   r^   r   rG   rG   rH   validate_read_preference_modex  s   r   c                 C  s.   ddl m} ||vrt|  dt| |S )z&Validate the authMechanism URI option.r   )
MECHANISMSz must be in )pymongo.auth_sharedr   r^   tuple)rW   rX   r   rG   rG   rH   validate_auth_mechanism  s   r   c                 C  s2   zt | W S  ty   t| dtt  dw )z<Validate the uuid representation option selected in the URI.z3 is an invalid UUID representation. Must be one of N)_UUID_REPRESENTATIONSKeyErrorr^   r   r   rG   rG   rH   validate_uuid_representation  s   
r   namelist[dict[str, str]]c              	   C  s   t |ts|g}g }|D ]=}|dkr|i  qz i }|dD ]}|d\}}t||t|< q || W q tyI   t|d|  dw |S )z5Parse readPreferenceTags if passed as a client kwarg. ,r>   z not a valid value for N)r]   listappendsplitr   	Exceptionr^   )r   rX   Ztag_setsZtag_settagstagrL   rh   rG   rG   rH   validate_read_preference_tags  s"   

r   )ZSERVICE_NAMEZSERVICE_HOSTr9   ZSERVICE_REALMAWS_SESSION_TOKENZENVIRONMENTZTOKEN_RESOURCEdict[str, Union[bool, str]]c           	      C  sv  i }t |tsnt |tstdt| | D ]R\}}t |tr'|||< qt |tr5t| ||< q|dv rCt |trC|||< q|dv r`ddl	m
} t ||s[tdt| |||< qtd| dt| |S t| |}t|}|d	D ]<}|d
\}}}|std|tvrd|v rtdt| dtt |dkrddlm} ||||< q||||< q||S )z!Validate authMechanismProperties.zIAuth mechanism properties must be given as a string or a dictionary, not )ZALLOWED_HOSTS)ZOIDC_CALLBACKZOIDC_HUMAN_CALLBACKr   )OIDCCallbackz-callback must be an OIDCCallback object, not z)Invalid type for auth mechanism property rQ   r   r>   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 r9   ) _validate_canonicalize_host_name)r]   r;   dictr^   rd   itemsrY   rJ   r   Zpymongo.auth_oidc_sharedr   rm   r   r   	partition_MECHANISM_PROPSr   r   r   )	rW   rX   propsrL   r   opt_rh   r   rG   rG   rH   "validate_auth_mechanism_properties  sR   









r   2Union[Type[MutableMapping], Type[RawBSONDocument]]c                 C  s`   d}zt |tj}W n ty   t|drt |jtj}Y n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   rc   hasattrr   r   )rW   rX   Z
is_mappingrG   rG   rH   validate_document_class  s   
r   Optional[TypeRegistry]c                 C  s(   |durt |tst|  dt |S )z"Validate the type_registry option.Nz must be an instance of )r]   r   rc   r_   rG   rG   rH   validate_type_registry  s   r   r   c                 C  s$   t |tst|  dt| |S )z!Validates that 'value' is a list.z must be a list, not )r]   r   rc   rd   r_   rG   rG   rH   validate_list  s   
r   c                 C  rq   )z)Validates that 'value' is a list or None.N)r   r_   rG   rG   rH   validate_list_or_none  rt   r   Nonec                 C  "   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)r]   r   r
   r   rc   r_   rG   rG   rH   validate_list_or_mapping  
   r   c                 C  s   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)r]   r   r
   rc   r_   rG   rG   rH   validate_is_mapping&  s
   r   c                 C  r   )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)r]   r   r   r   rc   r_   rG   rG   rH   validate_is_document_type0  r   r   c                 C  s:   |du r|S t | | t|ddkrt|  d|S )zValidate the appname option.Nzutf-8   z must be <= 128 bytes)rm   lenencoder^   r_   rG   rG   rH   validate_appname_or_none;  s   
r   Optional[DriverInfo]c                 C  s(   |du r|S t |tst|  d|S ) Validate the driver keyword arg.Nz" must be an instance of DriverInfo)r]   r   rc   r_   rG   rG   rH   validate_driver_or_noneF  s
   
r   Optional[ServerApi]c                 C  s0   |du r|S t |tst|  dt| |S )z$Validate the server_api keyword arg.Nz' must be an instance of ServerApi, not )r]   r!   rc   rd   r_   rG   rG   rH   validate_server_api_or_noneO  s
   
r   Optional[Callable]c                 C  s.   |du r|S t |st|  dt| |S )z%Validates that 'value' is a callable.Nz must be a callable, not )callabler^   rd   r_   rG   rG   rH   validate_is_callable_or_noneX  s
   r   replacementMapping[str, Any]c                 C  sB   t d|  | rt| tstt| }|drtddS dS dS )z Validate a replacement document.r   $z'replacement can not include $ operatorsN)r   r]   r   nextiterrC   r^   )r   firstrG   rG   rH   validate_ok_for_replacea  s   

r   updatec                 C  sL   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   r^   r]   r   r   r   rC   )r   Zis_documentr   rG   rG   rH   validate_ok_for_updatek  s   
r   )strictreplaceignorec                 C  s"   |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_HANDLERSr^   r   r   rG   rG   rH   %validate_unicode_decode_error_handler{  s   r   Optional[datetime.tzinfo]c                 C  s$   |durt |tjstd| |S )zValidate the tzinfo optionNz)%s must be an instance of datetime.tzinfo)r]   datetimetzinforc   r   rG   rG   rH   validate_tzinfo  s   r   Optional[Any]c                 C  s<   |du r|S ddl m} t||st|  dt| |S )r   Nr   )AutoEncryptionOptsz0 must be an instance of AutoEncryptionOpts, not )Zpymongo.encryption_optionsr   r]   rc   rd   )rW   rX   r   rG   rG   rH   %validate_auto_encryption_opts_or_none  s   
r   Optional[DatetimeConversion]c                 C  s\   |du r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   ZDATETIMEr]   r;   isdigitrB   rc   rd   r_   rG   rG   rH   validate_datetime_conversion  s   

r   c                 C  s    |dvrt |  d|d|S )z)Validate the serverMonitoringMode option.>   r8   pollstream=z7 is invalid. Must be one of "auto", "stream", or "poll")r^   r_   rG   rG   rH   validate_server_monitoring_mode  s
   r   tlssslzdict[str, list[str]]URI_OPTIONS_ALIAS_MAPappnameZauthmechanismauthmechanismpropertiesZ
authsourceZcompressorsconnecttimeoutmsZdirectconnectionheartbeatfrequencymsjournalZlocalthresholdmsmaxidletimemsZmaxconnectingZmaxpoolsizemaxstalenesssecondsZreadconcernlevelZreadpreferenceZreadpreferencetagsZ
replicasetZ
retryreadsZretrywritesZloadbalancedserverselectiontimeoutmssockettimeoutmsZtlsallowinvalidcertificatesZtlsallowinvalidhostnamesZ	tlscafileZtlscertificatekeyfileZtlscertificatekeyfilepasswordZtlsdisableocspendpointcheckZtlsinsecurew
wtimeoutmsZzlibcompressionlevel)ZsrvservicenameZsrvmaxhostsZ	timeoutmsZservermonitoringmode$dict[str, Callable[[Any, Any], Any]]URI_OPTIONS_VALIDATOR_MAP)connectZdriverZ
server_apifsyncZminpoolsizeZ
tlscrlfileZtz_awareZunicode_decode_error_handlerZuuidrepresentationZwaitqueuemultiplewaitqueuetimeoutmsZdatetime_conversionNONSPEC_OPTIONS_VALIDATOR_MAP)
Zdocument_classZtype_registryread_preferenceZevent_listenersr   usernamepasswordZserver_selectorZauto_encryption_optsZauthoidcallowedhostsKW_VALIDATORSzdict[str, str]INTERNAL_URI_OPTION_NAME_MAPzdict[str, tuple[str, str]]URI_OPTIONS_DEPRECATION_MAP
VALIDATORS)r   r   r   r   r   r   r   z	list[str]TIMEOUT_OPTIONStuple[str, Any]c                 C  s2   t | |\}}|tvrtd|  dt | |fS )z,Validate optional authentication parameters.rO   z. Must be in )validate_AUTH_OPTIONSr   )rW   rX   rJ   rG   rG   rH   validate_auth_option6  s   r  
validators
normed_keyr   c                 C  s@   |p| }z|| W S  t y   t||dd}t| | Y d S w )Ng?)cutoff)r   r   rT   )rL   r  r  rM   rG   rG   rH   _get_validator>  s   
r  c                 C  s$   t | t|  d}|| |}| |fS )zGeneric validation function.r  )r  r   rJ   )rW   rX   	validatorrG   rG   rH   r  I  s   
r  optionswarnMutableMapping[str, Any]c           
        s   t trt }ddd}dfdd}ni }ddd}dd	d} D ]U\}}||}zt|t|d
}|||}	W n8 tttfys   z)|dkr\t fddt	D r\dt
 vr\ |rhtjt
 dd n W Y d  q%d  ww |	|||< q%|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     | S NrG   r  rG   rG   rH   get_normed_key_     z-get_validated_options.<locals>.get_normed_keyc                   s
     | S r  )	cased_keyr  )r
  rG   rH   get_setter_keyb     
z-get_validated_options.<locals>.get_setter_keyc                 S  s   |   S r  )rJ   r  rG   rG   rH   r  h  s   c                 S  r  r  rG   r  rG   rG   rH   r  k  r  r  r   c                 3  s    | ]	}|t  v V  qd S r  r;   ).0p)excrG   rH   	<genexpr>v  s    z(get_validated_options.<locals>.<genexpr>z*is not a supported auth mechanism propertyr.   )
stacklevelN)r  r;   r<   r;   )r]   _CaseInsensitiveDictionaryr   r  r   r^   rc   r   any_MECH_PROP_MUST_RAISEr;   warningsr  )
r
  r  Zvalidated_optionsr  r  r   rX   r  r	  Z	validatedrG   )r  r
  rH   get_validated_optionsP  s4   



r   encrypted_fieldsc                 C     |  dd| dS )NZescCollectionenxcol_.z.escgetr!  r   rG   rG   rH   _esc_coll_name     r'  c                 C  r"  )NZecocCollectionr#  z.ecocr$  r&  rG   rG   rH   _ecoc_coll_name  r(  r)  )r   Zwtimeoutr   r   jr   c                   @  sf   e Zd ZdZdddZedddZedddZd ddZed!ddZ	d"ddZ
ed#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_optionsr   r   r    write_concernr#   read_concernr   r<   r   c                 C  s~   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 )r]   r   rc   _codec_optionsr    _read_preferencer#   rd   _write_concernr   _read_concern)selfr,  r   r-  r.  rG   rG   rH   __init__  s$   




zBaseObject.__init__c                 C     | j S )zdRead only access to the :class:`~bson.codec_options.CodecOptions`
        of this instance.
        )r/  r3  rG   rG   rH   r,    s   zBaseObject.codec_optionsc                 C  r5  )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.
        )r1  r6  rG   rG   rH   r-    s   zBaseObject.write_concernsession Optional[_AgnosticClientSession]c                 C  s   |r|j rtS | jS )zBRead only access to the write concern of this instance or session.)Zin_transactionr"   r-  r3  r7  rG   rG   rH   _write_concern_for  s   
zBaseObject._write_concern_forc                 C  r5  )zRead only access to the read preference of this instance.

        .. versionchanged:: 3.0
          The :attr:`read_preference` attribute is now read only.
        )r0  r6  rG   rG   rH   r        zBaseObject.read_preferencec                 C  s   |r	|  p| jS | jS )zDRead only access to the read preference of this instance or session.)Z_txn_read_preferencer0  r9  rG   rG   rH   _read_preference_for  s   zBaseObject._read_preference_forc                 C  r5  )zRead only access to the :class:`~pymongo.read_concern.ReadConcern`
        of this instance.

        .. versionadded:: 3.2
        )r2  r6  rG   rG   rH   r.    r;  zBaseObject.read_concernN)
r,  r   r   r    r-  r#   r.  r   r<   r   )r<   r   )r<   r#   )r7  r8  r<   r#   )r<   r    )r7  r8  r<   r    )r<   r   )__name__
__module____qualname____doc__r4  propertyr,  r-  r:  r   r<  r.  rG   rG   rG   rH   r+    s    

	
r+  c                   @  s   e Zd Zd4ddZd5d
dZd6ddZd7ddZd8ddZd9ddZd:ddZ	d;ddZ
d<ddZd=d>d"d#Zd?d$d%Zd@d'd(ZdAd)d*Zed=dBd+d,ZedCd-d,Zd=dDd.d,ZdEd0d1Zd:d2d3ZdS )Fr  argsr   kwargsc                 O  s$   i | _ i | _| t|i | d S r  )%_CaseInsensitiveDictionary__casedkeys _CaseInsensitiveDictionary__datar   r   )r3  rB  rC  rG   rG   rH   r4    s   z#_CaseInsensitiveDictionary.__init__rL   r;   r<   rY   c                 C  s   |  | jv S r  )rJ   rE  r3  rL   rG   rG   rH   __contains__     z'_CaseInsensitiveDictionary.__contains__rB   c                 C  s
   t | jS r  )r   rE  r6  rG   rG   rH   __len__  r  z"_CaseInsensitiveDictionary.__len__Iterator[str]c                 C  s   dd | j D S )Nc                 s  s    | ]}|V  qd S r  rG   )r  rL   rG   rG   rH   r    s    z6_CaseInsensitiveDictionary.__iter__.<locals>.<genexpr>)rD  r6  rG   rG   rH   __iter__  s   z#_CaseInsensitiveDictionary.__iter__c                   s   t  fdd D S )Nc                   s   i | ]} j |  j| qS rG   )rD  rE  )r  kr6  rG   rH   
<dictcomp>  s    z7_CaseInsensitiveDictionary.__repr__.<locals>.<dictcomp>r  r6  rG   r6  rH   __repr__  s   z#_CaseInsensitiveDictionary.__repr__rX   r   c                 C  s    |  }|| j|< || j|< d S r  rJ   rD  rE  )r3  rL   rX   lc_keyrG   rG   rH   __setitem__  s   
z&_CaseInsensitiveDictionary.__setitem__c                 C     | j |  S r  )rE  rJ   rF  rG   rG   rH   __getitem__  rH  z&_CaseInsensitiveDictionary.__getitem__c                 C  s   |  }| j|= | j|= d S r  rO  )r3  rL   rP  rG   rG   rH   __delitem__  s   z&_CaseInsensitiveDictionary.__delitem__otherc                 C  sH   t |tjstS t| t|krdS |D ]}| | || kr! dS qdS )NFT)r]   r   r
   NotImplementedr   r3  rU  rL   rG   rG   rH   __eq__  s   z!_CaseInsensitiveDictionary.__eq__Ndefaultr   c                 C  s   | j | |S r  )rE  r%  rJ   r3  rL   rY  rG   rG   rH   r%    s   z_CaseInsensitiveDictionary.getc                 O  s0   |  }| j|d  | jj|g|R i |S r  )rJ   rD  poprE  )r3  rL   rB  rC  rP  rG   rG   rH   r[    s   z_CaseInsensitiveDictionary.popr   c                 C  s"   | j  \}}| j|}||fS r  )rD  popitemrE  r[  )r3  rP  r  rX   rG   rG   rH   r\    s   z"_CaseInsensitiveDictionary.popitemc                 C  s   | j   | j  d S r  )rD  clearrE  r6  rG   rG   rH   r]    s   
z _CaseInsensitiveDictionary.clearc                 C     d S r  rG   rZ  rG   rG   rH   
setdefault"     z%_CaseInsensitiveDictionary.setdefaultc                 C  r^  r  rG   rZ  rG   rG   rH   r_  &  r`  c                 C  s2   |  }|| v r| j| S || j|< || j|< |S r  )rJ   rE  rD  )r3  rL   rY  rP  rG   rG   rH   r_  *  s   


r   c                 C  sD   t |tr|D ]}|| | ||< qd S |D ]}|| | |< qd S r  )r]   r  r  rW  rG   rG   rH   r   3  s   
z!_CaseInsensitiveDictionary.updatec                 C  rR  r  )rD  rJ   rF  rG   rG   rH   r  ;  rH  z$_CaseInsensitiveDictionary.cased_key)rB  r   rC  r   )rL   r;   r<   rY   )r<   rB   )r<   rJ  )r<   r;   )rL   r;   rX   r   r<   r   )rL   r;   r<   r   )rL   r;   r<   r   )rU  r   r<   rY   r  )rL   r;   rY  r   r<   r   )rL   r;   rB  r   rC  r   r<   r   )r<   r   )r<   r   )rL   r;   rY  r   r<   r   )rL   r;   rY  r   r<   r   )rL   r;   rY  r   r<   r   )rU  r   r<   r   )r=  r>  r?  r4  rG  rI  rK  rN  rQ  rS  rT  rX  r%  r[  r\  r]  r   r_  r   r  rG   rG   rG   rH   r    s*    












	r  c                  C  s(   z	ddl m}  W dS  ty   Y dS w )zIs the C extension installed?r   	_cmessageTF)Zpymongorb  ImportErrorra  rG   rG   rH   has_c?  s   rd  )r:   r;   r<   r=   r  )rL   r;   rM   rN   r<   r   )rW   r;   rX   r   r<   rY   )rW   r;   rX   r   r<   rB   )rW   r;   rX   r   r<   rl   )rW   r;   rX   r   r<   r/   )rW   r;   rX   r   r<   r;   )rW   r;   rX   r   r<   rw   )rW   r   rX   r   r<   rw   )rW   r;   rX   r   r<   r{   )rW   r;   rX   r   r<   r   )rW   r   rX   r   r<   r   )r   r   rX   r   r<   r    )r   r   rX   r   r<   rB   )r   r;   rX   r   r<   r   )rW   r;   rX   r   r<   r   )rW   r;   rX   r   r<   r   )rW   r   rX   r   r<   r   )rW   r;   rX   r   r<   r   )rW   r   rX   r   r<   rN   )rW   r   rX   r   r<   r   )rW   r;   rX   r   r<   r   )rW   r   rX   r   r<   r   )rW   r   rX   r   r<   r   )rW   r   rX   r   r<   r   )r   r   r<   r   )r   r   r<   r   )r   r   rX   r;   r<   r;   )r   r   rX   r   r<   r   )rW   r   rX   r   r<   r   )rW   r   rX   r   r<   r   )rW   r;   rX   r;   r<   r;   )rW   r;   rX   r   r<   r   )rL   r;   r  r   r  rl   r<   r   )T)r
  r   r  rY   r<   r  )r!  r   r   r;   r<   r   )r<   rY   )r@  
__future__r   r   r  collectionsr   r   difflibr   typingr   r   r   r	   r
   r   r   r   r   r   r   r   urllib.parser   Zbsonr   Zbson.binaryr   Zbson.codec_optionsr   r   r   Zbson.raw_bsonr   Zpymongo.compression_supportr   r   Zpymongo.driver_infor   Zpymongo.errorsr   Zpymongo.monitoringr   Zpymongo.read_concernr   Zpymongo.read_preferencesr   r    Zpymongo.server_apir!   Zpymongo.write_concernr"   r#   r$   Zpymongo.typingsr%   r&   __annotations__ZMAX_BSON_SIZEZMAX_MESSAGE_SIZEZMIN_WIRE_VERSIONZMAX_WIRE_VERSIONZMAX_WRITE_BATCH_SIZEZMIN_SUPPORTED_SERVER_VERSIONZMIN_SUPPORTED_WIRE_VERSIONZMAX_SUPPORTED_WIRE_VERSIONZHEARTBEAT_FREQUENCYZKILL_CURSOR_FREQUENCYZEVENTS_QUEUE_FREQUENCYZSERVER_SELECTION_TIMEOUTZMIN_HEARTBEAT_INTERVALZMIN_SRV_RESCAN_INTERVALZCONNECT_TIMEOUTZMAX_POOL_SIZEZMIN_POOL_SIZEZMAX_CONNECTINGr0   r1   r2   ZLOCAL_THRESHOLD_MSZRETRY_WRITESZRETRY_READSr5   r7   Z_MAX_END_SESSIONSZSRV_SERVICE_NAMEZSERVER_MONITORING_MODEr  rI   rK   rT   ZUNSPECIFIEDSTANDARDZPYTHON_LEGACYZJAVA_LEGACYZCSHARP_LEGACYr   r`   re   ri   rk   rp   rs   ru   rm   rv   ry   rz   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   r   r   r   r   r   r   r   optnamealiasesaliascopyr   r   r  r  r  r  r   r'  r)  ZWRITE_CONCERN_OPTIONSr+  r;   r  rd  rG   rG   rG   rH   <module>   s  8
				
		7

			
	
 !"#,




	3XX