o
    'hG2                     @  sR  d Z ddlmZ ddl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 ddlmZ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# erddl
m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, d3ddZ-d4d d!Z.d5d#d$Z/d6d&d'Z0d7d+d,Z1d8d.d/Z2G d0d1 d1Z3d2S )9zTools to parse mongo client options.

.. seealso:: This module is compatible with both the synchronous and asynchronous PyMongo APIs.
    )annotations)TYPE_CHECKINGAnyMappingOptionalSequencecast)_parse_codec_options)common)CompressionSettings)ConfigurationError)_EventListener_EventListeners)PoolOptions)ReadConcern)_ServerModemake_read_preferenceread_pref_mode_from_name)any_server_selector)get_ssl_context)WriteConcernvalidate_boolean)CodecOptions)MongoCredential)AutoEncryptionOpts)
SSLContext)_ServerSelectorusernamestrpassworddatabaseOptional[str]optionsMapping[str, Any]returnOptional[MongoCredential]c                 C  sH   | d| rdnd}| d}| s|r"ddlm} |||| |||S dS )z!Parse authentication credentials.authmechanismDEFAULTN
authsourcer   )_build_credentials_tuple)getpymongo.auth_sharedr)   )r   r   r    r"   	mechanismsourcer)    r.   R/var/www/html/olx_land/venv/lib/python3.10/site-packages/pymongo/client_options.py_parse_credentials/   s   
r0   r   c                 C  sF   d| v r| d S |  dd}t|}|  d}|  dd}t|||S )zParse read preference options.read_preferencereadpreferenceprimaryreadpreferencetagsmaxstalenessseconds)r*   r   r   )r"   namemodetagsmax_stalenessr.   r.   r/   _parse_read_preference<   s   
r;   r   c                 C  s6   |  d}|  d}|  d}|  d}t||||S )zParse write concern options.w
wtimeoutmsjournalfsync)r*   r   )r"   concernwtimeoutjr?   r.   r.   r/   _parse_write_concernH   s
   



rC   r   c                 C  s   |  d}t|S )zParse read concern options.readconcernlevel)r*   r   )r"   r@   r.   r.   r/   _parse_read_concernQ   s   
rE   is_syncbool!tuple[Optional[SSLContext], bool]c              	   C  s  |  d}|durtd| |  d}|  d}|  d}|  d}|  dd}|  d	d}|  d
d}	g }
dD ]}|| v rG| | rG|
| q8dD ]}|| v rY| | sY|
| qJ|
rn|du rcd}n|sntdd|
 |rt|||||||	|}||fS d|fS )zParse ssl options.tlsNtlscertificatekeyfiletlscertificatekeyfilepassword	tlscafile
tlscrlfiletlsallowinvalidcertificatesFtlsallowinvalidhostnamestlsdisableocspendpointcheck)rJ   rK   rL   rM   )rN   rO   rP   TzmTLS has not been enabled but the following tls parameters have been set: %s. Please set `tls=True` or remove.z, )r*   r   appendr   joinr   )r"   rF   use_tlscertfile
passphraseca_certscrlfileallow_invalid_certificatesallow_invalid_hostnamesdisable_ocsp_endpoint_checkenabled_tls_optsoptctxr.   r.   r/   _parse_ssl_optionsW   sR   








r^   r   c                 C  s  t | |||}|dtj}|dtj}|dtj}|dur(||kr(td|dtj}	|d}
|dtj}t	t
tt  |d	}|d
}|d}|d}t|dg |dd}t||\}}|d}|dtj}t||||	|
|||t|||||||||dS )zParse connection pool options.maxpoolsizeminpoolsizemaxidletimemsNz3minPoolSize must be smaller or equal to maxPoolSizeconnecttimeoutmssockettimeoutmswaitqueuetimeoutmsevent_listenersappnamedriver
server_apicompressorszlibcompressionlevelr6   loadbalancedmaxconnecting)max_connectingrh   load_balancedcredentialsrF   )r0   r*   r
   MAX_POOL_SIZEMIN_POOL_SIZEMAX_IDLE_TIME_SEC
ValueErrorCONNECT_TIMEOUTWAIT_QUEUE_TIMEOUTr   r   r   r   r   r^   MAX_CONNECTINGr   r   )r   r   r    r"   rF   ro   max_pool_sizemin_pool_sizemax_idle_time_secondsconnect_timeoutsocket_timeoutwait_queue_timeoutre   rf   rg   rh   compression_settingsssl_contexttls_allow_invalid_hostnamesrn   rm   r.   r.   r/   _parse_pool_options   sL   




r   c                   @  s6  e Zd ZdZ	dCdDddZedEddZedFddZedGddZedFddZ	edHddZ
edHddZedIdd ZedHd!d"ZedJd$d%ZedKd'd(ZedLd)d*ZedMd,d-ZedNd/d0ZedOd2d3ZedPd4d5ZedPd6d7ZedQd9d:ZedFd;d<ZedRd>d?ZedSd@dAZdBS )TClientOptionsa&  Read only configuration options for an AsyncMongoClient/MongoClient.

    Should not be instantiated directly by application developers. Access
    a client's options via :attr:`pymongo.mongo_client.AsyncMongoClient.options` or :attr:`pymongo.mongo_client.MongoClient.options`
    instead.
    Tr   r   r   r    r!   r"   r#   rF   rG   c                 C  s   || _ t|| _|d| _|dtj| _|dtj| _	t
|||||| _t|| _|d| _t|| _t|| _|d| _|dtj| _|dtj| _|dtj| _|d	t| _|d
| _|d| _|d| _|dtj| _ d S )Ndirectconnectionlocalthresholdmsserverselectiontimeoutms
replicasetconnectheartbeatfrequencymsretrywrites
retryreadsserver_selectorauto_encryption_optsrk   	timeoutmsservermonitoringmode)!_ClientOptions__optionsr	   _ClientOptions__codec_optionsr*   !_ClientOptions__direct_connectionr
   LOCAL_THRESHOLD_MS"_ClientOptions__local_threshold_msSERVER_SELECTION_TIMEOUT(_ClientOptions__server_selection_timeoutr   _ClientOptions__pool_optionsr;   _ClientOptions__read_preference _ClientOptions__replica_set_namerC   _ClientOptions__write_concernrE   _ClientOptions__read_concern_ClientOptions__connectHEARTBEAT_FREQUENCY#_ClientOptions__heartbeat_frequencyRETRY_WRITES_ClientOptions__retry_writesRETRY_READS_ClientOptions__retry_readsr   _ClientOptions__server_selector$_ClientOptions__auto_encryption_opts_ClientOptions__load_balanced_ClientOptions__timeoutSERVER_MONITORING_MODE&_ClientOptions__server_monitoring_mode)selfr   r   r    r"   rF   r.   r.   r/   __init__   s.   




zClientOptions.__init__r$   c                 C     | j S )z7The original options used to create this ClientOptions.)r   r   r.   r.   r/   _options      zClientOptions._optionsOptional[bool]c                 C  r   )z>Whether to begin discovering a MongoDB topology automatically.)r   r   r.   r.   r/   r      r   zClientOptions.connectr   c                 C  r   )z5A :class:`~bson.codec_options.CodecOptions` instance.)r   r   r.   r.   r/   codec_options   r   zClientOptions.codec_optionsc                 C  r   )z:Whether to connect to the deployment in 'Single' topology.)r   r   r.   r.   r/   direct_connection   r   zClientOptions.direct_connectionintc                 C  r   )z&The local threshold for this instance.)r   r   r.   r.   r/   local_threshold_ms  r   z ClientOptions.local_threshold_msc                 C  r   )z:The server selection timeout for this instance in seconds.)r   r   r.   r.   r/   server_selection_timeout  r   z&ClientOptions.server_selection_timeoutr   c                 C  r   )N)r   r   r.   r.   r/   r     s   zClientOptions.server_selectorc                 C  r   )z$The monitoring frequency in seconds.)r   r   r.   r.   r/   heartbeat_frequency  r   z!ClientOptions.heartbeat_frequencyr   c                 C  r   )z.A :class:`~pymongo.pool.PoolOptions` instance.)r   r   r.   r.   r/   pool_options  r   zClientOptions.pool_optionsr   c                 C  r   )zA read preference instance.)r   r   r.   r.   r/   r1     r   zClientOptions.read_preferencec                 C  r   )zReplica set name or None.)r   r   r.   r.   r/   replica_set_name   r   zClientOptions.replica_set_namer   c                 C  r   )z8A :class:`~pymongo.write_concern.WriteConcern` instance.)r   r   r.   r.   r/   write_concern%  r   zClientOptions.write_concernr   c                 C  r   )z6A :class:`~pymongo.read_concern.ReadConcern` instance.)r   r   r.   r.   r/   read_concern*  r   zClientOptions.read_concernOptional[float]c                 C  r   )z_The configured timeoutMS converted to seconds, or None.

        .. versionadded:: 4.2
        )r   r   r.   r.   r/   timeout/     zClientOptions.timeoutc                 C  r   )z9If this instance should retry supported write operations.)r   r   r.   r.   r/   retry_writes7  r   zClientOptions.retry_writesc                 C  r   )z8If this instance should retry supported read operations.)r   r   r.   r.   r/   retry_reads<  r   zClientOptions.retry_readsOptional[AutoEncryptionOpts]c                 C  r   )z:A :class:`~pymongo.encryption.AutoEncryptionOpts` or None.)r   r   r.   r.   r/   r   A  r   z"ClientOptions.auto_encryption_optsc                 C  r   )z@True if the client was configured to connect to a load balancer.)r   r   r.   r.   r/   rn   F  r   zClientOptions.load_balancedlist[_EventListeners]c                 C  s   | j jdusJ | j j S )zThe event listeners registered for this client.

        See :mod:`~pymongo.monitoring` for details.

        .. versionadded:: 4.0
        N)r   _event_listenersre   r   r.   r.   r/   re   K  s   zClientOptions.event_listenersc                 C  r   )zSThe configured serverMonitoringMode option.

        .. versionadded:: 4.5
        )r   r   r.   r.   r/   server_monitoring_modeV  r   z$ClientOptions.server_monitoring_modeN)T)
r   r   r   r   r    r!   r"   r#   rF   rG   )r$   r#   )r$   r   )r$   r   )r$   r   )r$   r   )r$   r   )r$   r   )r$   r!   )r$   r   )r$   r   )r$   r   )r$   rG   )r$   r   )r$   r   )r$   r   )__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r   r   r   r   r1   r   r   r   r   r   r   r   rn   re   r   r.   r.   r.   r/   r      sX    "
r   N)
r   r   r   r   r    r!   r"   r#   r$   r%   )r"   r#   r$   r   )r"   r#   r$   r   )r"   r#   r$   r   )r"   r#   rF   rG   r$   rH   )r   r   r   r   r    r!   r"   r#   rF   rG   r$   r   )4r   
__future__r   typingr   r   r   r   r   r   bson.codec_optionsr	   pymongor
   pymongo.compression_supportr   pymongo.errorsr   pymongo.monitoringr   r   pymongo.pool_optionsr   pymongo.read_concernr   pymongo.read_preferencesr   r   r   pymongo.server_selectorsr   pymongo.ssl_supportr   pymongo.write_concernr   r   r   r+   r   pymongo.encryption_optionsr   pymongo.pyopenssl_contextr   pymongo.topology_descriptionr   r0   r;   rC   rE   r^   r   r   r.   r.   r.   r/   <module>   s6    



	

>0