U
    ~fh"                  '   @  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r<ddl7m8Z8 eefZ9de:d< dZ;de; Z<de:d< 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:d0< d1ZUd2ZVd3ZWd4d5d6d7d8ZXd4d5d6d9d:ZYdd4d;d<d=d>d?ZZej[ej\ej]ej^ej_d@Z`d4dAdBdCdDdEZad4dAddCdFdGZbd4dAddCdHdIZcd4dAddCdJdKZdd4dAdLdCdMdNZed4dAd&dCdOdPZfd4dAd&dCdQdRZgd4dAd4dCdSdTZhd4dAdLdCdUdVZid4dAdWdCdXdYZjdAdAdWdCdZd[Zkd4dAd\dCd]d^Zld4dAd\dCd_d`Zmd4dAdadCdbdcZnd4dAd\dCdddeZodAdAdadCdfdgZpdAdAdadCdhdiZqd4dAddCdjdkZrdAdAdldmdndoZsdAdAdldmdpdqZtd4dAd4dCdrdsZudAdAddmdtduZvd4dAdvdwdxdyZwexdzd{d|d}d~dgZyd4dAddCddZzd4dAddCddZ{dAdAddCddZ|d4dAddCddZ}dAdAd;dCddZ~dAdAddCddZd4dAddCddZd4dAddCddZd4dAdLdCddZdAdAddCddZdAdAddCddZdAdAddCddZdddddZdAddddZexdddgZdAd4d4dmddZdAdAddmddZdAdAddCddZdAdAddCddZd4d4d4dCddZddgiZde:d< eeuezehe$epeaeneaemenecegereieteweieaeaeaeoepeaeaeaeeeeeieaeaekede%ehedeqed&Zde:d< eaeeeaedeeeaeevegenedZde:d< e{e|ese+eeieieee}d
Zde:d< ddiZde:d< i Zde:d< ee e D ],\ZZeD ]ZeekrBee ee< qBq6e Zde:d< ee dddddddgZde:d< exdgZd4dAddCddӄZdd4ddLdd՜ddׄZd4dAddCddلZdddBddۜdd݄Zdd4dAdޜddZdd4dAdޜddZexddddddgZG dd dZG dd deeef ZdBddd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      intMAX_MESSAGE_SIZEi  z3.6      
         g      ?<   g      4@d   z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strztuple[str, int])nodereturnc                 C  sZ   | }d}|  d}|dkr<| d| t| |d d  }}|drR|dd }||fS )z5Split a host:port string into (host, int(port)) pair.ii  :Nr-   [)rfindr(   
startswith)r;   hostportidx rE   2/tmp/pip-unpacked-wheel-36gvocj8/pymongo/common.pypartition_node   s    
"
rG   c                 C  s   t | \}}| |fS )z6Split and normalize a node name from a hello response.)rG   lower)r;   rB   rC   rE   rE   rF   
clean_node   s    rI   zOptional[list]r   )keysuggestionsr<   c                 C  s2   d|  d}|r&|dd | d7 }t|dS )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.N)joinr   )rJ   rK   msgrE   rE   rF   raise_config_error   s    rQ   )unspecifiedstandardZpythonLegacyZ
javaLegacyZcsharpLegacyr   bool)optionvaluer<   c                 C  s4   t |tr*|dk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'rW   )
isinstancer:   
ValueErrorr$   rU   rV   rE   rE   rF   validate_boolean_or_string   s
    
r]   c                 C  s^   t |tr|S t |trJz
t|W S  tk
rH   td|  ddY nX td|  ddS )zDValidates that 'value' is an integer (or basestring representation).rY   z must be an integerNWrong type for z, value must be an integerrZ   r(   r:   r[   	TypeErrorr\   rE   rE   rF   validate_integer   s    


ra   c                 C  s&   t | |}|dkr"td|  d|S )zFValidate that 'value' is a positive integer, which does not include 0.r   rY   z must be a positive integerra   r[   rU   rV   valrE   rE   rF   validate_positive_integer   s    
re   c                 C  s&   t | |}|dk r"td|  d|S )z1Validate that 'value' is a positive integer or 0.r   rY   z must be a non negative integerrb   rc   rE   rE   rF   validate_non_negative_integer   s    
rf   zOptional[str]c                 C  s&   |dkr|S t | |}t|  |S )z1Validates that 'value' is file-like and readable.N)validate_stringopencloser\   rE   rE   rF   validate_readable   s
    
rj   c                 C  s   |dkr|S t | |S )z4Validate that 'value' is a positive integer or None.Nre   r\   rE   rE   rF   !validate_positive_integer_or_none   s    rl   c                 C  s   |dkr|S t | |S )z9Validate that 'value' is a positive integer or 0 or None.N)rf   r\   rE   rE   rF   %validate_non_negative_integer_or_none   s    rm   c                 C  s"   t |tr|S td|  ddS )z/Validates that 'value' is an instance of `str`.r^   z", value must be an instance of strN)rZ   r:   r`   r\   rE   rE   rF   rg      s    
rg   c                 C  s   |dkr|S t | |S )z@Validates that 'value' is an instance of `basestring` or `None`.N)rg   r\   rE   rE   rF   validate_string_or_none   s    rn   zUnion[int, str]c                 C  sP   t |tr|S t |tr<z
t|W S  tk
r:   | Y S X td|  ddS )/Validates that 'value' is an integer or string.r^   z&, value must be an integer or a stringNr_   r\   rE   rE   rF   validate_int_or_basestring  s    



rp   c                 C  s\   t |tr|S t |trHzt|}W n tk
r<   | Y S X t| |S td|  ddS )ro   r^   z3, value must be an non negative integer or a stringN)rZ   r(   r:   r[   rf   r`   rc   rE   rE   rF   'validate_non_negative_int_or_basestring  s    



rq   floatc                 C  sz   |  d}zt |}W n: tk
r4   t|dY n tk
rP   t|dY nX d|  k rfdk svn 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)rr   r[   r`   )rU   rV   errmsgrE   rE   rF   validate_positive_float  s    
rt   c                 C  s   |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rt   r\   rE   rE   rF   validate_positive_float_or_zero0  s    rw   zOptional[float]c                 C  s   |dkr|S t | |d S zcValidates a timeout specified in milliseconds returning
    a value in floating point seconds.
    N     @@rv   r\   rE   rE   rF   validate_timeout_or_none9  s    rz   c                 C  s8   |dk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   ru   ry   )r   rt   r\   rE   rE   rF   validate_timeout_or_zeroB  s
    r{   c                 C  s*   |dk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   ru   ry   rv   r\   rE   rE   rF    validate_timeout_or_none_or_zeroO  s    r|   c                 C  s   |dkrdS t | |d S rx   )rw   r\   rE   rE   rF   validate_timeoutmsY  s    r}   c                 C  s   |dks|dkrdS t | |S )zBValidates maxStalenessSeconds according to the Max Staleness Spec.r>   z-1rk   r\   rE   rE   rF   validate_max_stalenessb  s    r~   r    )dummyrV   r<   c                 C  s   t |tst|d|S )zValidate a read preference.z is not a read preference.)rZ   r    r`   r   rV   rE   rE   rF   validate_read_preferencej  s    
r   c                 C  s   |t k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   rE   rE   rF   validate_read_preference_modeq  s    r   c                 C  s.   ddl m} ||kr*t|  dt| |S )z&Validate the authMechanism URI option.r   )
MECHANISMSz must be in )Zpymongo.auth_sharedr   r[   tuple)rU   rV   r   rE   rE   rF   validate_auth_mechanism}  s    r   c                 C  s<   z
t | W S  tk
r6   t| dtt  dY nX dS )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   rE   rE   rF   validate_uuid_representation  s    
r   zlist[dict[str, str]])namerV   r<   c              	   C  s   t |ts|g}g }|D ]}|dkr0|i  qz@i }|dD ]"}|d\}}t||t|< q@|| W q tk
r   t|d|  dY qX q|S )z5Parse readPreferenceTags if passed as a client kwarg. ,r=   z not a valid value for N)rZ   listappendsplitr   	Exceptionr[   )r   rV   Ztag_setsZtag_settagstagrJ   rd   rE   rE   rF   validate_read_preference_tags  s     

r   ZSERVICE_NAMECANONICALIZE_HOST_NAMEZSERVICE_REALMAWS_SESSION_TOKENZENVIRONMENTZTOKEN_RESOURCEzdict[str, Union[bool, str]]c                 C  sd  i }t |tst |ts td| D ]\}}t |trD|||< q(t |tr`t| ||< q(|dkr|t |tr||||< q(|dkrddlm	} t ||std|||< q(td| dt
| q(|S t| |}t|}|d	D ]x}|d
\}}}|std|tkr<d|kr$tdt| dtt d|dkrVt||||< q|||< q|S )z!Validate authMechanismProperties.zCAuth mechanism properties must be given as a string or a dictionary)ZALLOWED_HOSTS)ZOIDC_CALLBACKZOIDC_HUMAN_CALLBACKr   )OIDCCallbackz'callback must be an OIDCCallback objectz)Invalid type for auth mechanism property rN   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 rM   r   )rZ   r:   dictr[   itemsrT   rH   r   Zpymongo.auth_oidc_sharedr   typerg   r   r   	partition_MECHANISM_PROPSr   r]   )rU   rV   propsrJ   r   opt_rd   rE   rE   rF   "validate_auth_mechanism_properties  sH    












r   z2Union[Type[MutableMapping], Type[RawBSONDocument]]c                 C  sb   d}zt |tj}W n, tk
r@   t|dr<t |jtj}Y nX |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   r`   hasattrr   r   )rU   rV   Z
is_mappingrE   rE   rF   validate_document_class  s    
r   zOptional[TypeRegistry]c                 C  s(   |dk	r$t |ts$t|  dt |S )z"Validate the type_registry option.Nz must be an instance of )rZ   r   r`   r\   rE   rE   rF   validate_type_registry  s    r   r   c                 C  s   t |tst|  d|S )z!Validates that 'value' is a list.z must be a list)rZ   r   r`   r\   rE   rE   rF   validate_list  s    
r   c                 C  s   |dkr|S t | |S )z)Validates that 'value' is a list or None.N)r   r\   rE   rE   rF   validate_list_or_none	  s    r   Nonec                 C  s"   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)rZ   r   r
   r   r`   r\   rE   rE   rF   validate_list_or_mapping  s    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)rZ   r   r
   r`   r\   rE   rE   rF   validate_is_mapping  s    r   c                 C  s"   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)rZ   r   r   r   r`   r\   rE   rE   rF   validate_is_document_type$  s    r   c                 C  s:   |dkr|S t | | t|ddkr6t|  d|S )zValidate the appname option.Nzutf-8   z must be <= 128 bytes)rg   lenencoder[   r\   rE   rE   rF   validate_appname_or_none/  s    
r   zOptional[DriverInfo]c                 C  s(   |dkr|S t |ts$t|  d|S ) Validate the driver keyword arg.Nz" must be an instance of DriverInfo)rZ   r   r`   r\   rE   rE   rF   validate_driver_or_none:  s
    
r   zOptional[ServerApi]c                 C  s(   |dkr|S t |ts$t|  d|S )z$Validate the server_api keyword arg.Nz! must be an instance of ServerApi)rZ   r!   r`   r\   rE   rE   rF   validate_server_api_or_noneC  s
    
r   zOptional[Callable]c                 C  s&   |dkr|S t |s"t|  d|S )z%Validates that 'value' is a callable.Nz must be a callable)callabler[   r\   rE   rE   rF   validate_is_callable_or_noneL  s
    r   Mapping[str, Any])replacementr<   c                 C  s:   t d|  | r6t| ts6tt| }|dr6tddS )z Validate a replacement document.r   $z'replacement can not include $ operatorsN)r   rZ   r   nextiterrA   r[   )r   firstrE   rE   rF   validate_ok_for_replaceU  s
    

r   )updater<   c                 C  sH   t d|  | stdt| t }tt| }|rD|dsDtddS )zValidate an update document.r   zupdate cannot be emptyr   z"update only works with $ operatorsN)r   r[   rZ   r   r   r   rA   )r   Zis_documentr   rE   rE   rF   validate_ok_for_update_  s    
r   strictreplaceignorec                 C  s"   |t k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   rE   rE   rF   %validate_unicode_decode_error_handlero  s
    r   zOptional[datetime.tzinfo]c                 C  s$   |dk	r t |tjs td| |S )zValidate the tzinfo optionNz)%s must be an instance of datetime.tzinfo)rZ   datetimetzinfor`   r   rE   rE   rF   validate_tzinfoz  s    r   Optional[Any]c                 C  s4   |dkr|S ddl m} t||s0t|  d|S )r   Nr   )AutoEncryptionOptsz* must be an instance of AutoEncryptionOpts)Zpymongo.encryption_optionsr   rZ   r`   )rU   rV   r   rE   rE   rF   %validate_auto_encryption_opts_or_none  s    
r   zOptional[DatetimeConversion]c                 C  sX   |dkrt jS t|tr4| r,t t|S t | S t|trFt |S t|  ddS )z%Validate a DatetimeConversion string.Nz5 must be a str or int representing DatetimeConversion)r   ZDATETIMErZ   r:   isdigitr(   r`   r\   rE   rE   rF   validate_datetime_conversion  s    

r   c                 C  s    |dkrt |  d|d|S )z)Validate the serverMonitoringMode option.>   pollstreamr9   =z7 is invalid. Must be one of "auto", "stream", or "poll")r[   r\   rE   rE   rF   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sockettimeoutmsr   ZtlsallowinvalidcertificatesZtlsallowinvalidhostnamesZ	tlscafileZtlscertificatekeyfileZtlscertificatekeyfilepasswordZtlsdisableocspendpointcheckZtlsinsecurew
wtimeoutmsZzlibcompressionlevelZsrvservicenameZsrvmaxhostsZ	timeoutmsZservermonitoringmodez$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
VALIDATORSr   r   r   r   r   r   r   z	list[str]TIMEOUT_OPTIONSr   tuple[str, Any]c                 C  s2   t | |\}}|tkr*td|  dt | |fS )z,Validate optional authentication parameters.rL   z. Must be in )validate_AUTH_OPTIONSr   )rU   rV   rH   rE   rE   rF   validate_auth_option(  s    r   r   )rJ   
validators
normed_keyr<   c                 C  sD   |p| }z
|| W S  t k
r>   t||dd}t| | Y nX d S )Ng?)cutoff)r   r   rQ   )rJ   r   r   rK   rE   rE   rF   _get_validator0  s    
r   c                 C  s$   t | t|  d}|| |}| |fS )zGeneric validation function.r   )r   r   rH   )rU   rV   	validatorrE   rE   rF   r   ;  s    
r   zMutableMapping[str, Any])optionswarnr<   c                   s   t  tr6t }ddddd}ddd fdd}n$i }ddddd}ddddd}  D ]|\}}||}zt|t|d	}|||}	W nB tttfk
r }
 z|rtj	t
|
d
d n W 5 d}
~
X Y qbX |	|||< qb|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.
    r:   )xr<   c                 S  s   | S NrE   r   rE   rE   rF   get_normed_keyQ  s    z-get_validated_options.<locals>.get_normed_keyc                   s
     | S r   )	cased_keyr   r   rE   rF   get_setter_keyT  s    z-get_validated_options.<locals>.get_setter_keyc                 S  s   |   S r   )rH   r   rE   rE   rF   r   Z  s    c                 S  s   | S r   rE   r   rE   rE   rF   r   ]  s    r   r'   )
stacklevelN)rZ   _CaseInsensitiveDictionaryr   r   r   r[   r`   r   warningsr   r:   )r   r   Zvalidated_optionsr   r   r   rV   r   r   Z	validatedexcrE   r   rF   get_validated_optionsB  s$    
r   )encrypted_fieldsr   r<   c                 C  s   |  dd| dS )NZescCollectionenxcol_.z.escgetr   r   rE   rE   rF   _esc_coll_nameo  s    r  c                 C  s   |  dd| dS )NZecocCollectionr  z.ecocr  r  rE   rE   rF   _ecoc_coll_names  s    r  r   Zwtimeoutr   r   jr   c                   @  s   e Zd ZdZdddddddd	Zedd
ddZedd
ddZdddddZedd
ddZ	dddddZ
ed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.
    r   r    r#   r   r   )codec_optionsr   write_concernread_concernr<   c                 C  sj   t |tstd|| _t |ts0t|d|| _t |tsHtd|| _t |ts`td|| _	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.zGwrite_concern must be an instance of pymongo.write_concern.WriteConcernzDread_concern must be an instance of pymongo.read_concern.ReadConcern)
rZ   r   r`   _codec_optionsr    _read_preferencer#   _write_concernr   _read_concern)selfr	  r   r
  r  rE   rE   rF   __init__  s     



zBaseObject.__init__r<   c                 C  s   | j S )zdRead only access to the :class:`~bson.codec_options.CodecOptions`
        of this instance.
        )r  r  rE   rE   rF   r	    s    zBaseObject.codec_optionsc                 C  s   | 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  rE   rE   rF   r
    s    zBaseObject.write_concernz Optional[_AgnosticClientSession])sessionr<   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
  r  r  rE   rE   rF   _write_concern_for  s    
zBaseObject._write_concern_forc                 C  s   | 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  rE   rE   rF   r     s    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_preferencer  r  rE   rE   rF   _read_preference_for  s    zBaseObject._read_preference_forc                 C  s   | j S )zRead only access to the :class:`~pymongo.read_concern.ReadConcern`
        of this instance.

        .. versionadded:: 3.2
        )r  r  rE   rE   rF   r    s    zBaseObject.read_concernN)__name__
__module____qualname____doc__r  propertyr	  r
  r  r   r  r  rE   rE   rE   rF   r  {  s   	r  c                   @  s>  e Zd ZdddddZddddd	Zd
dddZddddZddddZddddddZdddddZ	dddddZ
dddddZd4dddd d!d"Zddddd#d$d%Zd&dd'd(Zddd)d*Zed5dddd d+d,Zedddd d-d,Zd6dddd d.d,Zd/ddd0d1Zdddd2d3ZdS )7r   r   )argskwargsc                 O  s    i | _ i | _| t|| d S r   )%_CaseInsensitiveDictionary__casedkeys _CaseInsensitiveDictionary__datar   r   )r  r  r  rE   rE   rF   r    s    z#_CaseInsensitiveDictionary.__init__r:   rT   )rJ   r<   c                 C  s   |  | jkS r   )rH   r   r  rJ   rE   rE   rF   __contains__  s    z'_CaseInsensitiveDictionary.__contains__r(   r  c                 C  s
   t | jS r   )r   r   r  rE   rE   rF   __len__  s    z"_CaseInsensitiveDictionary.__len__zIterator[str]c                 C  s   dd | j D S )Nc                 s  s   | ]
}|V  qd S r   rE   ).0rJ   rE   rE   rF   	<genexpr>  s     z6_CaseInsensitiveDictionary.__iter__.<locals>.<genexpr>)r  r  rE   rE   rF   __iter__  s    z#_CaseInsensitiveDictionary.__iter__c                   s   t  fdd D S )Nc                   s   i | ]} j |  j| qS rE   )r  r   )r$  kr  rE   rF   
<dictcomp>  s      z7_CaseInsensitiveDictionary.__repr__.<locals>.<dictcomp>)r:   r  rE   r  rF   __repr__  s    z#_CaseInsensitiveDictionary.__repr__r   )rJ   rV   r<   c                 C  s    |  }|| j|< || j|< d S r   rH   r  r   )r  rJ   rV   lc_keyrE   rE   rF   __setitem__  s    
z&_CaseInsensitiveDictionary.__setitem__c                 C  s   | j |  S r   )r   rH   r!  rE   rE   rF   __getitem__  s    z&_CaseInsensitiveDictionary.__getitem__c                 C  s   |  }| j|= | j|= d S r   r*  )r  rJ   r+  rE   rE   rF   __delitem__  s    z&_CaseInsensitiveDictionary.__delitem__)otherr<   c                 C  sH   t |tjstS t| t|kr$dS |D ]}| | || kr( dS q(dS )NFT)rZ   r   r
   NotImplementedr   r  r/  rJ   rE   rE   rF   __eq__  s    z!_CaseInsensitiveDictionary.__eq__Nr   )rJ   defaultr<   c                 C  s   | j | |S r   )r   r  rH   r  rJ   r3  rE   rE   rF   r    s    z_CaseInsensitiveDictionary.get)rJ   r  r  r<   c                 O  s*   |  }| j|d  | jj|f||S r   )rH   r  popr   )r  rJ   r  r  r+  rE   rE   rF   r5    s    z_CaseInsensitiveDictionary.popr   c                 C  s"   | j  \}}| j|}||fS r   )r  popitemr   r5  )r  r+  r   rV   rE   rE   rF   r6    s    z"_CaseInsensitiveDictionary.popitemc                 C  s   | j   | j  d S r   )r  clearr   r  rE   rE   rF   r7    s    
z _CaseInsensitiveDictionary.clearc                 C  s   d S r   rE   r4  rE   rE   rF   
setdefault  s    z%_CaseInsensitiveDictionary.setdefaultc                 C  s   d S r   rE   r4  rE   rE   rF   r8    s    c                 C  s6   |  }|| kr| j| S || j|< || j|< |S d S r   )rH   r   r  )r  rJ   r3  r+  rE   rE   rF   r8    s    


r   c                 C  sB   t |tr(|D ]}|| | ||< qn|D ]}|| | |< q,d S r   )rZ   r   r   r1  rE   rE   rF   r     s
    
z!_CaseInsensitiveDictionary.updatec                 C  s   | j |  S r   )r  rH   r!  rE   rE   rF   r   %  s    z$_CaseInsensitiveDictionary.cased_key)N)N)N)r  r  r  r  r"  r#  r&  r)  r,  r-  r.  r2  r  r5  r6  r7  r   r8  r   r   rE   rE   rE   rF   r     s(   	r   r  c                  C  s.   zddl m}  W dS  tk
r(   Y dS X dS )zIs the C extension installed?r   	_cmessageTFN)Zpymongor:  ImportErrorr9  rE   rE   rF   has_c)  s
    r<  )N)N)T)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_SIZEr)   Z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_CONNECTINGr1   r2   r3   ZLOCAL_THRESHOLD_MSZRETRY_WRITESZRETRY_READSr6   r8   Z_MAX_END_SESSIONSZSRV_SERVICE_NAMEZSERVER_MONITORING_MODErG   rI   rQ   ZUNSPECIFIEDZSTANDARDZPYTHON_LEGACYZJAVA_LEGACYZCSHARP_LEGACYr   r]   ra   re   rf   rj   rl   rm   rg   rn   rp   rq   rt   rw   rz   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   r<  rE   rE   rE   rF   <module>   s  8
				
		3

			
 	, 




	  -VX