U
    dC                  &   @  s4  U d Z ddlmZ ddlZddlZddlZddlmZ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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& ddl'm(Z(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9m:Z: e
rPddl;m<Z< eefZ=de>d< dZ?de? Z@de>d< dZAdZBdZCdZDdZEdZFdZGd ZHd ZId!ZJd"ZKd#ZLd$ZMd%ZNdZOdZPdZQd&e>d'< dZRd&e>d(< dZSd&e>d)< d*ZTd+ZUd+ZVd,ZWd-e>d.< d/ZXd-e>d0< d1ZYd2ZZd3d4d5d6d7Z[d3d4d5d8d9Z\d3d:d;d<d=d>Z]ej^ej_ej`ejaejbd?Zcd3d:d@dAdBdCZdd3d:ddAdDdEZed3d:ddAdFdGZfd3d:ddAdHdIZgd3d:dJdAdKdLZhd3d:d&dAdMdNZid3d:d&dAdOdPZjd3d:d3dAdQdRZkd3d:dJdAdSdTZld3d:dUdAdVdWZmd:d:dUdAdXdYZnd3d:dZdAd[d\Zod3d:dZdAd]d^Zpd3d:d_dAd`daZqd3d:dZdAdbdcZrd:d:d_dAdddeZsd:d:d_dAdfdgZtd3d:ddAdhdiZud:d:djdkdldmZvd:d:djdkdndoZwd3d:d3dAdpdqZxd:d:ddkdrdsZyd3d:dtdudvdwZze{dxdydzd{d|gZ|d3d:d}dAd~dZ}d3d:ddAddZ~d:d:ddAddZd3d:ddAddZd:d:ddAddZd:d:ddAddZd3d:ddAddZd3d:ddAddZd3d:dJdAddZd:d:ddAddZd:d:ddAddZd:d:ddAddZdddddZd:ddddZe{dddgZd:d3d3dkddZd:d:ddkddZd:d:ddAddZd:d:ddAddZddgiZde>d< eexe}eke(esedeqedepeqefejeuelewezelededederesedededehehelededenege)ekegetd%Zde>d< edeeedegehedeeyejeqedZde>d< e~eeve/eeleleeed
Zde>d< ddiZde>d< i Zde>d< ee e D ],\ZZeD ]Zeekr:ee ee< q:q.e Zde>d< ee dddddddgZde>d< e{dgZd3d:ddAddτZd3d:ddAddфZddd@ddӜddՄZdd3d:d֜dd؄Zdd3d:d֜ddڄZe{ddddddgZG dd dZG dd deeef ZdS )z9Functions and classes common to multiple pymongo modules.    )annotationsN)OrderedDictabc)TYPE_CHECKINGAnyCallableDictIteratorListMappingMutableMappingNoReturnOptionalSequenceTupleTypeUnionoverload)unquote_plus)SON)UuidRepresentation)CodecOptionsDatetimeConversionTypeRegistry)RawBSONDocument)
MECHANISMS)validate_compressorsvalidate_zlib_compression_level)
DriverInfoConfigurationError)_validate_event_listeners)ReadConcern)_MONGOS_MODES_ServerMode)	ServerApi)DEFAULT_WRITE_CONCERNWriteConcernvalidate_boolean)ClientSessionz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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  :Nr1   [)rfindr,   
startswith)r>   hostportidx rH   2/tmp/pip-unpacked-wheel-oblwsawz/pymongo/common.pypartition_node   s    
"
rJ   c                 C  s   t | \}}| |fS )z6Split and normalize a node name from a hello response.)rJ   lower)r>   rE   rF   rH   rH   rI   
clean_node   s    rL   r   r   )keydummyr?   c                 C  s   t d|  dS )z1Raise ConfigurationError with the given key name.zUnknown option Nr   )rM   rN   rH   rH   rI   raise_config_error   s    rO   )unspecifiedstandardZpythonLegacyZ
javaLegacyZcsharpLegacy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'rU   )
isinstancer=   
ValueErrorr(   rS   rT   rH   rH   rI   validate_boolean_or_string   s
    
r[   c                 C  s\   t |tr|S t |trHz
t|W S  tk
rF   td|  dY nX td|  ddS )zDValidates that 'value' is an integer (or basestring representation).rW   z must be an integerWrong type for z, value must be an integerNrX   r,   r=   rY   	TypeErrorrZ   rH   rH   rI   validate_integer   s    


r_   c                 C  s&   t | |}|dkr"td|  d|S )zFValidate that 'value' is a positive integer, which does not include 0.r   rW   z must be a positive integerr_   rY   rS   rT   valrH   rH   rI   validate_positive_integer   s    
rc   c                 C  s&   t | |}|dk r"td|  d|S )z1Validate that 'value' is a positive integer or 0.r   rW   z must be a non negative integerr`   ra   rH   rH   rI   validate_non_negative_integer   s    
rd   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closerZ   rH   rH   rI   validate_readable   s
    
rh   c                 C  s   |dkr|S t | |S )z4Validate that 'value' is a positive integer or None.Nrc   rZ   rH   rH   rI   !validate_positive_integer_or_none   s    rj   c                 C  s   |dkr|S t | |S )z9Validate that 'value' is a positive integer or 0 or None.N)rd   rZ   rH   rH   rI   %validate_non_negative_integer_or_none   s    rk   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)rX   r=   r^   rZ   rH   rH   rI   re      s    
re   c                 C  s   |dkr|S t | |S )z@Validates that 'value' is an instance of `basestring` or `None`.N)re   rZ   rH   rH   rI   validate_string_or_none   s    rl   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]   rZ   rH   rH   rI   validate_int_or_basestring  s    



rn   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 )rm   r\   z3, value must be an non negative integer or a stringN)rX   r,   r=   rY   rd   r^   ra   rH   rH   rI   'validate_non_negative_int_or_basestring  s    



ro   floatc                 C  sv   |  d}zt |}W n6 tk
r2   t|Y n tk
rL   t|Y nX d|  k rbdk srn t|  d|S )zXValidates that 'value' is a float, or can be converted to one, and is
    positive.
    z must be an integer or floatr   g    eAz1 must be greater than 0 and less than one billion)rp   rY   r^   )rS   rT   errmsgrH   rH   rI   validate_positive_float  s    
rr   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rr   rZ   rH   rH   rI   validate_positive_float_or_zero-  s    ru   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     @@rt   rZ   rH   rH   rI   validate_timeout_or_none6  s    rx   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   rs   rw   )r    rr   rZ   rH   rH   rI   validate_timeout_or_zero?  s
    ry   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   rs   rw   rt   rZ   rH   rH   rI    validate_timeout_or_none_or_zeroL  s    rz   c                 C  s   |dkrdS t | |d S rv   )ru   rZ   rH   rH   rI   validate_timeoutmsV  s    r{   c                 C  s   |dks|dkrdS t | |S )zBValidates maxStalenessSeconds according to the Max Staleness Spec.rA   z-1ri   rZ   rH   rH   rI   validate_max_staleness_  s    r|   r$   )rN   rT   r?   c                 C  s   t |tst|d|S )zValidate a read preference.z is not a read preference.)rX   r$   r^   rN   rT   rH   rH   rI   validate_read_preferenceg  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#   rY   r}   rH   rH   rI   validate_read_preference_moden  s    r   c                 C  s"   |t krt|  dtt  |S )z&Validate the authMechanism URI option.z must be in )r   rY   tuplerZ   rH   rH   rI   validate_auth_mechanismz  s    r   c              	   C  s8   z
t | W S  tk
r2   td|tt Y nX dS )z<Validate the uuid representation option selected in the URI.z7{} is an invalid UUID representation. Must be one of {}N)_UUID_REPRESENTATIONSKeyErrorrY   formatr   r}   rH   rH   rI   validate_uuid_representation  s    
 r   zList[Dict[str, str]])namerT   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|  Y qX q|S )z5Parse readPreferenceTags if passed as a client kwarg. ,r@   z not a valid value for )rX   listappendsplitr   	ExceptionrY   )r   rT   Ztag_setsZtag_settagstagrM   rb   rH   rH   rI   validate_read_preference_tags  s     

r   ZSERVICE_NAMECANONICALIZE_HOST_NAMEZSERVICE_REALMAWS_SESSION_TOKENZPROVIDER_NAMEzDict[str, Union[bool, str]]c           	   	   C  s  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(t	|rt
|}|dkrd}n|dkrd}ntd| t|j|kr| d| d}t||||< q(td	q(|S t| |}|d
D ]}z|d\}}W n2 tk
rT   d|krBd}td|Y nX |tkrttd|tt|dkrt||||< nt|||< q|S )z!Validate authMechanismProperties.zCAuth mechanism properties must be given as a string or a dictionary)Zallowed_hostsZrequest_token_callbackr+   Zrefresh_token_callbackz%Unrecognized Auth mechanism function z must accept z parameterszDAuth mechanism property values must be strings or callback functionsr   r@   r   z_AWS_SESSION_TOKEN:<redacted token>, did you forget to percent-escape the token with quote_plus?zTauth mechanism properties must be key:value pairs like SERVICE_NAME:mongodb, not {}.zA{} is not a supported auth mechanism property. Must be one of {}.r   )rX   r=   dictrY   itemsrR   rK   r   inspect
isfunction	signaturelen
parametersre   r   r   _MECHANISM_PROPSr   r[   r   )	rS   rT   propsrM   r   Zexpected_paramsmsgoptrb   rH   rH   rI   "validate_auth_mechanism_properties  sd    












 
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__zi{} must be dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a subclass of collections.MutableMapping)
issubclassr   r   r^   hasattrr   r   r   )rS   rT   Z
is_mappingrH   rH   rI   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 )rX   r   r^   rZ   rH   rH   rI   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)rX   r   r^   rZ   rH   rH   rI   validate_list  s    
r   zOptional[List]c                 C  s   |dkr|S t | |S )z)Validates that 'value' is a list or None.N)r   rZ   rH   rH   rI   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.zw{} must either be a list or an instance of dict, bson.son.SON, or any other type that inherits from collections.MappingN)rX   r   r   r   r^   r   rZ   rH   rH   rI   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.zf{} must be an instance of dict, bson.son.SON, or any other type that inherits from collections.MappingN)rX   r   r   r^   r   rZ   rH   rH   rI   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)rX   r   r   r   r^   r   rZ   rH   rH   rI   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)re   r   encoderY   rZ   rH   rH   rI   validate_appname_or_none3  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)rX   r   r^   rZ   rH   rH   rI   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)rX   r%   r^   rZ   rH   rH   rI   validate_server_api_or_noneG  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)callablerY   rZ   rH   rH   rI   validate_is_callable_or_noneP  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   rX   r   nextiterrD   rY   )r   firstrH   rH   rI   validate_ok_for_replaceY  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   rY   rX   r   r   r   rD   )r   Zis_documentr   rH   rH   rI   validate_ok_for_updatec  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_HANDLERSrY   r   r   r}   rH   rH   rI   %validate_unicode_decode_error_handlers  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)rX   datetimetzinfor^   r}   rH   rH   rI   validate_tzinfo~  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   rX   r^   )rS   rT   r   rH   rH   rI   %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DATETIMErX   r=   isdigitr,   r^   rZ   rH   rH   rI   validate_datetime_conversion  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$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  s,   t | |\}}|tkr$td|  | |fS )z,Validate optional authentication parameters.zUnknown authentication option: )validate_AUTH_OPTIONSr    )rS   rT   rK   rH   rH   rI   validate_auth_option#  s    r   c                 C  s&   |   }t|t}|| |}| |fS )zGeneric validation function.)rK   r   getrO   )rS   rT   rK   	validatorrH   rH   rI   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 ]v\}}||}zt|t}|||}W n> tttfk
r }	 z|rt	
t|	 n W 5 d	}	~	X Y qbX ||||< qb|S )
a  Validate each entry in options and raise a warning if it is not valid.
    Returns a copy of options with invalid entries removed.

    :Parameters:
        - `opts`: A dict containing MongoDB URI options.
        - `warn` (optional): 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 NrH   r   rH   rH   rI   get_normed_keyC  s    z-get_validated_options.<locals>.get_normed_keyc                   s
     | S r   )	cased_keyr   r   rH   rI   get_setter_keyF  s    z-get_validated_options.<locals>.get_setter_keyc                 S  s   |   S r   )rK   r   rH   rH   rI   r   L  s    c                 S  s   | S r   rH   r   rH   rH   rI   r   O  s    N)rX   _CaseInsensitiveDictionaryr   r   r   rO   rY   r^   r    warningsr   r=   )
r   r   Zvalidated_optionsr   r   r   rT   Z
normed_keyr   excrH   r   rI   get_validated_options3  s$    
r   )encrypted_fieldsr   r?   c                 C  s   |  dd| dS )NZescCollectionenxcol_.z.escr   r   r   rH   rH   rI   _esc_coll_namea  s    r   c                 C  s   |  dd| dS )NZecocCollectionr   z.ecocr   r   rH   rH   rI   _ecoc_coll_namee  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.CodecOptionszV{!r} 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)rX   r   r^   _BaseObject__codec_optionsr$   r   _BaseObject__read_preferencer'   _BaseObject__write_concernr"   _BaseObject__read_concern)selfr   r   r   r   rH   rH   rI   __init__t  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  rH   rH   rI   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  rH   rH   rI   r     s    zBaseObject.write_concernzOptional[ClientSession])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  rH   rH   rI   _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  rH   rH   rI   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	  rH   rH   rI   _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  rH   rH   rI   r     s    zBaseObject.read_concernN)__name__
__module____qualname____doc__r  propertyr   r   r
  r   r  r   rH   rH   rH   rI   r   m  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  rH   rH   rI   r    s    z#_CaseInsensitiveDictionary.__init__r=   rR   )rM   r?   c                 C  s   |  | jkS r   )rK   r  r  rM   rH   rH   rI   __contains__  s    z'_CaseInsensitiveDictionary.__contains__r,   r  c                 C  s
   t | jS r   )r   r  r  rH   rH   rI   __len__  s    z"_CaseInsensitiveDictionary.__len__zIterator[str]c                 C  s   dd | j D S )Nc                 s  s   | ]
}|V  qd S r   rH   ).0rM   rH   rH   rI   	<genexpr>  s     z6_CaseInsensitiveDictionary.__iter__.<locals>.<genexpr>)r  r  rH   rH   rI   __iter__  s    z#_CaseInsensitiveDictionary.__iter__c                   s   t  fdd D S )Nc                   s   i | ]} j |  j| qS rH   )r  r  )r  kr  rH   rI   
<dictcomp>  s      z7_CaseInsensitiveDictionary.__repr__.<locals>.<dictcomp>)r=   r  rH   r  rI   __repr__  s    z#_CaseInsensitiveDictionary.__repr__r   )rM   rT   r?   c                 C  s    |  }|| j|< || j|< d S r   rK   r  r  )r  rM   rT   lc_keyrH   rH   rI   __setitem__  s    
z&_CaseInsensitiveDictionary.__setitem__c                 C  s   | j |  S r   )r  rK   r  rH   rH   rI   __getitem__  s    z&_CaseInsensitiveDictionary.__getitem__c                 C  s   |  }| j|= | j|= d S r   r  )r  rM   r  rH   rH   rI   __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)rX   r   r   NotImplementedr   r  r#  rM   rH   rH   rI   __eq__  s    z!_CaseInsensitiveDictionary.__eq__Nr   )rM   defaultr?   c                 C  s   | j | |S r   )r  r   rK   r  rM   r'  rH   rH   rI   r     s    z_CaseInsensitiveDictionary.get)rM   r  r  r?   c                 O  s*   |  }| j|d  | jj|f||S r   )rK   r  popr  )r  rM   r  r  r  rH   rH   rI   r)    s    z_CaseInsensitiveDictionary.popr   c                 C  s"   | j  \}}| j|}||fS r   )r  popitemr  r)  )r  r  r   rT   rH   rH   rI   r*    s    z"_CaseInsensitiveDictionary.popitemc                 C  s   | j   | j  d S r   )r  clearr  r  rH   rH   rI   r+    s    
z _CaseInsensitiveDictionary.clearc                 C  s   d S r   rH   r(  rH   rH   rI   
setdefault  s    z%_CaseInsensitiveDictionary.setdefaultc                 C  s   d S r   rH   r(  rH   rH   rI   r,    s    c                 C  s6   |  }|| kr| j| S || j|< || j|< |S d S r   )rK   r  r  )r  rM   r'  r  rH   rH   rI   r,    s    


r   c                 C  sB   t |tr(|D ]}|| | ||< qn|D ]}|| | |< q,d S r   )rX   r   r   r%  rH   rH   rI   r     s
    
z!_CaseInsensitiveDictionary.updatec                 C  s   | j |  S r   )r  rK   r  rH   rH   rI   r     s    z$_CaseInsensitiveDictionary.cased_key)N)N)N)r  r  r  r  r  r  r  r  r   r!  r"  r&  r   r)  r*  r+  r   r,  r   r   rH   rH   rH   rI   r     s(   	r   )T)r  
__future__r   r   r   r   collectionsr   r   typingr   r   r   r   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.authr   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.client_sessionr)   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_CONNECTINGr5   r6   r7   ZLOCAL_THRESHOLD_MSZRETRY_WRITESZRETRY_READSr:   r<   Z_MAX_END_SESSIONSZSRV_SERVICE_NAMErJ   rL   rO   ZUNSPECIFIEDZSTANDARDZPYTHON_LEGACYZJAVA_LEGACYZCSHARP_LEGACYr   r[   r_   rc   rd   rh   rj   rk   re   rl   rn   ro   rr   ru   rx   ry   rz   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   optnamealiasesaliascopyr   r   r   r   r   r   r   r   ZWRITE_CONCERN_OPTIONSr   r=   r   rH   rH   rH   rI   <module>   s  D				
	=

			
 	+ 



	 .V