o
    sDi
                     @  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 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/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8m9Z9 erddl:m;Z; eefZ<de=d< dZ>dZ?dZ@dZAdZBdZCdZDdZEdZFdZGdZHd ZId!ZJd"ZKd#ZLd$ZMdZNd%ZOdZPd&e=d'< dZQd&e=d(< dZRd&e=d)< d*ZSd+ZTd+ZUd,ZVd-e=d.< d/ZWd-e=d0< d1ZXd2ZYd3ZZd4gZ[dd9d:Z\dd;d<Z]dddAdBZ^ej_ej`ejaejbejcdCZdddHdIZeddKdLZfddMdNZgddOdPZhddRdSZiddTdUZjddVdWZkddXdYZlddZd[Zmdd]d^Zndd_d`ZoddbdcZpddddeZqddgdhZrddidjZsddkdlZtddmdnZuddodpZvddsdtZwddudvZxddwdxZyddydzZzdd}d~Z{e|g d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Zd'ddZe|g dZd(ddZd)ddZd*ddZd+ddZd,ddZddgiZde=d< i dedeyde~delde'detdeederdeedeqderdegdekdevdemdexde{i demdeedeedeedesdetdeedeedeedeideidemdeedeedeodehde(eleheuedۜZde=d< eeeeeeeheieeeezekeredޜZde=d< eeewe.eememeeed
Zde=d< ddiZde=d< i Zde=d< ee e D ]\ZZeD ]Zeevree ee< qqe Zde=d< ee g dZde=d< e|dgZd-ddZ	dd.ddZd-ddZ	+d/d0ddZd1ddZd1ddZe|g dZG dd  d ZG dd deeef Zd2ddZG dd deedf Zd3d
dZdS (4  z9Functions and classes common to multiple pymongo modules.    )annotationsN)OrderedDictabc)get_close_matches)requiresversion)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                 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 rJ   L/home/alumno/antzosa8961/venv/lib/python3.10/site-packages/pymongo/common.pypartition_node   s   
"
rL   c                 C  s   t | \}}| |fS )z6Split and normalize a node name from a hello response.)rL   lower)r=   rG   rH   rJ   rJ   rK   
clean_node   s   rN   keysuggestionsOptional[list[str]]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   )rO   rP   msgrJ   rJ   rK   raise_config_error   s   rW   )unspecifiedstandardpythonLegacy
javaLegacy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'r`   )
isinstancer>   
ValueErrorr&   r]   r^   rJ   rJ   rK   validate_boolean_or_string   s
   

rf   rE   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).rb   z must be an integerNWrong type for z , value must be an integer, not rc   rE   r>   rd   	TypeErrortypere   rJ   rJ   rK   validate_integer   s   


rk   c                 C  s&   t | |}|dkrtd|  d|S )zFValidate that 'value' is a positive integer, which does not include 0.r   rb   z must be a positive integerrk   rd   r]   r^   valrJ   rJ   rK   validate_positive_integer      
ro   c                 C  s&   t | |}|dk rtd|  d|S )z1Validate that 'value' is a positive integer or 0.r   rb   z must be a non negative integerrl   rm   rJ   rJ   rK   validate_non_negative_integer   rp   rq   Optional[str]c                 C  s&   |du r|S t | |}t|  |S )z1Validates that 'value' is file-like and readable.N)validate_stringopenclosere   rJ   rJ   rK   validate_readable   s
   
rv   c                 C     |du r|S t | |S )z4Validate that 'value' is a positive integer or None.Nro   re   rJ   rJ   rK   !validate_positive_integer_or_none      
ry   c                 C  rw   )z9Validate that 'value' is a positive integer or 0 or None.N)rq   re   rJ   rJ   rK   %validate_non_negative_integer_or_none   rz   r{   c                 C  s&   t |tr|S td|  dt| )z/Validates that 'value' is an instance of `str`.rg   z(, value must be an instance of str, not )rc   r>   ri   rj   re   rJ   rJ   rK   rs      s   
rs   c                 C  rw   )z@Validates that 'value' is an instance of `basestring` or `None`.N)rs   re   rJ   rJ   rK   validate_string_or_none  rz   r|   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.rg   z,, value must be an integer or a string, not rh   re   rJ   rJ   rK   validate_int_or_basestring  s   


r   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| )r~   rg   z9, value must be an non negative integer or a string, not )rc   rE   r>   rd   rq   ri   rj   rm   rJ   rJ   rK   'validate_non_negative_int_or_basestring  s   


r   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   rd   ri   )r]   r^   errmsgrJ   rJ   rK   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   re   rJ   rJ   rK   validate_positive_float_or_zero8  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   re   rJ   rJ   rK   validate_timeout_or_noneA     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   re   rJ   rJ   rK   validate_timeout_or_zeroJ  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   re   rJ   rJ   rK    validate_timeout_or_none_or_zeroW  s   r   c                 C  s   |du rdS t | |d S r   )r   re   rJ   rJ   rK   validate_timeoutmsa  r   r   c                 C  r   )zBValidates maxStalenessSeconds according to the Max Staleness Spec.rB   z-1rx   re   rJ   rJ   rK   validate_max_stalenessj  s   
r   dummyr"   c                 C  s   t |tst|d|S )zValidate a read preference.z is not a read preference)rc   r"   ri   r   r^   rJ   rJ   rK   validate_read_preferencer  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!   rd   r   rJ   rJ   rK   validate_read_preference_modey  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   rd   tuple)r]   r^   r   rJ   rJ   rK   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KeyErrorrd   r   r   rJ   rJ   rK   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. ,rA   z not a valid value for N)rc   listappendsplitr   	Exceptionrd   )r   r^   tag_setstag_settagstagrO   rn   rJ   rJ   rK   validate_read_preference_tags  s"   

r   )SERVICE_NAMESERVICE_HOSTr<   SERVICE_REALMAWS_SESSION_TOKENENVIRONMENT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 )ALLOWED_HOSTS)OIDC_CALLBACKOIDC_HUMAN_CALLBACKr   )OIDCCallbackz-callback must be an OIDCCallback object, not z)Invalid type for auth mechanism property rT   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)rc   r>   dictrd   rj   itemsr_   rM   r   pymongo.auth_oidc_sharedr   rs   r   r   	partition_MECHANISM_PROPSr   r   r   )	r]   r^   propsrO   r   opt_rn   r   rJ   rJ   rK   "validate_auth_mechanism_properties  sR   









r   <Union[Type[MutableMapping[str, Any]], 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   ri   hasattrr   r   )r]   r^   
is_mappingrJ   rJ   rK   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 )rc   r   ri   re   rJ   rJ   rK   validate_type_registry  s   r   	list[Any]c                 C  s$   t |tst|  dt| |S )z!Validates that 'value' is a list.z must be a list, not )rc   r   ri   rj   re   rJ   rJ   rK   validate_list  s   
r   Optional[list[Any]]c                 C  rw   )z)Validates that 'value' is a list or None.N)r   re   rJ   rJ   rK   validate_list_or_none  rz   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)rc   r   r   r   ri   re   rJ   rJ   rK   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)rc   r   r   ri   re   rJ   rJ   rK   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)rc   r   r   r   ri   re   rJ   rJ   rK   validate_is_document_type1  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)rs   lenencoderd   re   rJ   rJ   rK   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)rc   r   ri   re   rJ   rJ   rK   validate_driver_or_noneG  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 )rc   r#   ri   rj   re   rJ   rJ   rK   validate_server_api_or_noneP  s
   
r   Optional[Callable[..., Any]]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 )callablerd   rj   re   rJ   rJ   rK   validate_is_callable_or_noneY  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   rc   r   nextiterrF   rd   )r   firstrJ   rJ   rK   validate_ok_for_replaceb  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   rd   rc   r   r   r   rF   )r   is_documentr   rJ   rJ   rK   validate_ok_for_updatel  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_HANDLERSrd   r   r   rJ   rJ   rK   %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)rc   datetimetzinfori   r   rJ   rJ   rK   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 )pymongo.encryption_optionsr   rc   ri   rj   )r]   r^   r   rJ   rJ   rK   %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   DATETIMErc   r>   isdigitrE   ri   rj   re   rJ   rJ   rK   validate_datetime_conversion  s   

r   c                 C  s    |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")rd   re   rJ   rJ   rK   validate_server_monitoring_mode  s
   r   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  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.rR   z. Must be in )validate_AUTH_OPTIONSr   )r]   r^   rM   rJ   rJ   rK   validate_auth_option7  s   rC  
validators
normed_keyCallable[[Any, Any], Any]c                 C  s@   |p| }z|| W S  t y   t||dd}t| | Y d S w )Ng?)cutoff)r   r   rW   )rO   rD  rE  rP   rJ   rJ   rK   _get_validator?  s   
rH  c                 C  s$   t | t|  d}|| |}| |fS )zGeneric validation function.rE  )rH  r>  rM   )r]   r^   	validatorrJ   rJ   rK   rA  J  s   
rA  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 NrJ   rN  rJ   rJ   rK   get_normed_key`     z-get_validated_options.<locals>.get_normed_keyc                   s
     | S rP  )	cased_keyrQ  )rK  rJ   rK   get_setter_keyc     
z-get_validated_options.<locals>.get_setter_keyc                 S  s   |   S rP  )rM   rQ  rJ   rJ   rK   rR  i  s   c                 S  rO  rP  rJ   rQ  rJ   rJ   rK   rU  l  rS  rI  r   c                 3  s    | ]	}|t  v V  qd S rP  r>   ).0p)excrJ   rK   	<genexpr>w  s    z(get_validated_options.<locals>.<genexpr>z*is not a supported auth mechanism propertyr0   )
stacklevelN)rN  r>   r?   r>   )rc   _CaseInsensitiveDictionaryr   rH  r$  rd   ri   r   any_MECH_PROP_MUST_RAISEr>   warningsrL  )
rK  rL  validated_optionsrR  rU  r   r^   rE  rJ  	validatedrJ   )rZ  rK  rK   get_validated_optionsQ  s4   



rc  encrypted_fieldsc                 C     |  dd| dS )NescCollectionenxcol_.z.escgetrd  r   rJ   rJ   rK   _esc_coll_name     rk  c                 C  re  )NecocCollectionrg  z.ecocrh  rj  rJ   rJ   rK   _ecoc_coll_name  rl  rn  )r  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_optionsCodecOptions[Any]r4  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 )rc   r   ri   _codec_optionsr"   _read_preferencer%   rj   _write_concernr    _read_concern)selfrr  r4  rt  ru  rJ   rJ   rK   __init__  s$   




zBaseObject.__init__c                 C     | j S )zdRead only access to the :class:`~bson.codec_options.CodecOptions`
        of this instance.
        )rv  rz  rJ   rJ   rK   rr    s   zBaseObject.codec_optionsc                 C  r|  )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.
        )rx  r}  rJ   rJ   rK   rt    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.)in_transactionr$   rt  rz  r~  rJ   rJ   rK   _write_concern_for  s   
zBaseObject._write_concern_forc                 C  r|  )zRead only access to the read preference of this instance.

        .. versionchanged:: 3.0
          The :attr:`read_preference` attribute is now read only.
        )rw  r}  rJ   rJ   rK   r4       zBaseObject.read_preferencec                 C  s   |r	|  p| jS | jS )zDRead only access to the read preference of this instance or session.)_txn_read_preferencerw  r  rJ   rJ   rK   _read_preference_for  s   zBaseObject._read_preference_forc                 C  r|  )zRead only access to the :class:`~pymongo.read_concern.ReadConcern`
        of this instance.

        .. versionadded:: 3.2
        )ry  r}  rJ   rJ   rK   ru    r  zBaseObject.read_concernN)
rr  rs  r4  r"   rt  r%   ru  r    r?   r   )r?   rs  )r?   r%   )r~  r  r?   r%   )r?   r"   )r~  r  r?   r"   )r?   r    )__name__
__module____qualname____doc__r{  propertyrr  rt  r  r4  r  ru  rJ   rJ   rJ   rK   rq    s    

	
rq  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 rP  )%_CaseInsensitiveDictionary__casedkeys _CaseInsensitiveDictionary__datar   r   )rz  r  r  rJ   rJ   rK   r{    s   z#_CaseInsensitiveDictionary.__init__rO   r>   r?   r_   c                 C  s   |  | jv S rP  )rM   r  rz  rO   rJ   rJ   rK   __contains__     z'_CaseInsensitiveDictionary.__contains__rE   c                 C  s
   t | jS rP  )r   r  r}  rJ   rJ   rK   __len__  rV  z"_CaseInsensitiveDictionary.__len__Iterator[str]c                 C  s   dd | j D S )Nc                 s  s    | ]}|V  qd S rP  rJ   )rX  rO   rJ   rJ   rK   r[    s    z6_CaseInsensitiveDictionary.__iter__.<locals>.<genexpr>)r  r}  rJ   rJ   rK   __iter__     z#_CaseInsensitiveDictionary.__iter__c                   s   t  fdd D S )Nc                   s   i | ]} j |  j| qS rJ   )r  r  )rX  kr}  rJ   rK   
<dictcomp>  s    z7_CaseInsensitiveDictionary.__repr__.<locals>.<dictcomp>rW  r}  rJ   r}  rK   __repr__  s   z#_CaseInsensitiveDictionary.__repr__r^   r   c                 C  s    |  }|| j|< || j|< d S rP  rM   r  r  )rz  rO   r^   lc_keyrJ   rJ   rK   __setitem__  s   
z&_CaseInsensitiveDictionary.__setitem__c                 C     | j |  S rP  )r  rM   r  rJ   rJ   rK   __getitem__  r  z&_CaseInsensitiveDictionary.__getitem__c                 C  s   |  }| j|= | j|= d S rP  r  )rz  rO   r  rJ   rJ   rK   __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)rc   r   r   NotImplementedr   rz  r  rO   rJ   rJ   rK   __eq__  s   z!_CaseInsensitiveDictionary.__eq__Ndefaultr   c                 C  s   | j | |S rP  )r  ri  rM   rz  rO   r  rJ   rJ   rK   ri    s   z_CaseInsensitiveDictionary.getc                 O  s0   |  }| j|d  | jj|g|R i |S rP  )rM   r  popr  )rz  rO   r  r  r  rJ   rJ   rK   r    s   z_CaseInsensitiveDictionary.popr@  c                 C  s"   | j  \}}| j|}||fS rP  )r  popitemr  r  )rz  r  rT  r^   rJ   rJ   rK   r    s   z"_CaseInsensitiveDictionary.popitemc                 C  s   | j   | j  d S rP  )r  clearr  r}  rJ   rJ   rK   r    s   
z _CaseInsensitiveDictionary.clearc                 C     d S rP  rJ   r  rJ   rJ   rK   
setdefault#     z%_CaseInsensitiveDictionary.setdefaultc                 C  r  rP  rJ   r  rJ   rJ   rK   r  '  r  c                 C  s2   |  }|| v r| j| S || j|< || j|< |S rP  )rM   r  r  )rz  rO   r  r  rJ   rJ   rK   r  +  s   


r   c                 C  sD   t |tr|D ]}|| | ||< qd S |D ]}|| | |< qd S rP  )rc   r]  rT  r  rJ   rJ   rK   r   4  s   
z!_CaseInsensitiveDictionary.updatec                 C  r  rP  )r  rM   r  rJ   rJ   rK   rT  <  r  z$_CaseInsensitiveDictionary.cased_key)r  r	   r  r	   )rO   r>   r?   r_   )r?   rE   )r?   r  r?   r>   )rO   r>   r^   r	   r?   r   )rO   r>   r?   r	   )rO   r>   r?   r   )r  r	   r?   r_   rP  )rO   r>   r  r   r?   r	   )rO   r>   r  r	   r  r	   r?   r	   )r?   r@  )r?   r   )rO   r>   r  r   r?   r   )rO   r>   r  r	   r?   r	   )rO   r>   r  r   r?   r   )r  r   r?   r   )r  r  r  r{  r  r  r  r  r  r  r  r  ri  r  r  r  r   r  r   rT  rJ   rJ   rJ   rK   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)pymongor  ImportErrorr  rJ   rJ   rK   has_c@  s   r  c                      sb   e Zd ZdZd fddZeddddZedddZed ddZd!ddZ	d"ddZ
  ZS )#Versionz4A class that can be used to compare version strings.r   rE   r?   c                   s   |  |d}t | t|S )N   )_paddedsuper__new__r   )clsr   padded_version	__class__rJ   rK   r  M  s   zVersion.__new__r   r   r	   lengthpadding	list[int]c                 C  s8   t |}t||k rt|t| D ]}|| q|S rP  )r   r   ranger   )r  r   r  r  as_listr   rJ   rJ   rK   r  Q  s
   zVersion._paddedversion_stringr>   c                 C  s   d}d}| dr|dd }d}n| dr |dd }d}n| dr-|dd }d}d	|v r<|d|d	 }d}d
|v rL|d|d
 }d}nd|v r]|d|d }d}d}dd |dD }| |d}|rw|d  d7  < || t| S )Nr   F+rB   r,   z-pre--z.devz-rcTc                 S  s   g | ]}t |qS rJ   )rE   )rX  partrJ   rJ   rK   
<listcomp>t  s    z'Version.from_string.<locals>.<listcomp>rS      )endswithfindr   r  r   r  )r  r  modbump_patch_levelr   rJ   rJ   rK   from_stringY  s6   



zVersion.from_stringversion_arrayc                 C  s0   t |}|d dk rd|d< | |d}t| S )NrB   r   r  )r   r  r  )r  r  r   rJ   rJ   rK   from_version_array  s
   zVersion.from_version_arrayother_versionr_   c                 G  s   | t | kS rP  )r  )rz  r  rJ   rJ   rK   at_least  s   zVersion.at_leastc                 C  s   d tt| S )NrS   )rU   mapr>   r}  rJ   rJ   rK   __str__  r  zVersion.__str__)r   rE   r?   r  )r   )r   r	   r  rE   r  rE   r?   r  )r  r>   r?   r  )r  r	   r?   r  )r  r	   r?   r_   r  )r  r  r  r  r  classmethodr  r  r  r  r  __classcell__rJ   rJ   r  rK   r  J  s    '
r  .package_nametuple[str, str, bool]c                   s   t  }t|}td}|dusJ  fdd|D d }d|v r)|dd }||dd d }|t|k}|||fS )	z<Test whether an installed package is of the desired version.r  Nc                   s   g | ]	}|  r|qS rJ   )rF   )rX  ir  rJ   rK   r    s    z)check_for_min_version.<locals>.<listcomp>r   ;z>=r0   )r   r  r  r   r   r  )r  package_version_strpackage_versionrequirementsrequirementrequired_versionis_validrJ   r  rK   check_for_min_version  s   

r  )r=   r>   r?   r@   rP  )rO   r>   rP   rQ   r?   r   )r]   r>   r^   r	   r?   r_   )r]   r>   r^   r	   r?   rE   )r]   r>   r^   r	   r?   rr   )r]   r>   r^   r	   r?   r1   )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?   r@  )rO   r>   rD  r#  rE  rr   r?   rF  )T)rK  r   rL  r_   r?   rM  )rd  r   r   r>   r?   r	   )r?   r_   )r  r>   r?   r  )r  
__future__r   r   r`  collectionsr   r   difflibr   importlib.metadatar   r   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_CONNECTINGr2   r3   r4   LOCAL_THRESHOLD_MSRETRY_WRITESRETRY_READSr7   r9   _MAX_END_SESSIONSSRV_SERVICE_NAMESERVER_MONITORING_MODEr_  rL   rN   rW   UNSPECIFIEDSTANDARDPYTHON_LEGACYJAVA_LEGACYCSHARP_LEGACYr   rf   rk   ro   rq   rv   ry   r{   rs   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   r$  r1  r;  r<  r=  r   r   optnamealiasesaliascopyr>  r?  rB  rC  rH  rA  rc  rk  rn  WRITE_CONCERN_OPTIONSrq  r>   r]  r  r   rE   r  r  rJ   rJ   rJ   rK   <module>   s  8
				
		7

			
	
 !"#,




	3XX 
F