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.ZauthmechanismDEFAULTNZ
authsourcer   )_build_credentials_tuple)getpymongo.auth_sharedr'   )r   r   r    r"   Z	mechanismsourcer'    r+   I/var/www/html/venv/lib/python3.10/site-packages/pymongo/client_options.py_parse_credentials/   s   
r-   r   c                 C  sF   d| v r| d S |  dd}t|}|  d}|  dd}t|||S )zParse read preference options.read_preferenceZreadpreferenceprimaryZreadpreferencetagsZmaxstalenessseconds)r(   r   r   )r"   namemodetagsZmax_stalenessr+   r+   r,   _parse_read_preference<   s   
r4   r   c                 C  s6   |  d}|  d}|  d}|  d}t||||S )zParse write concern options.wZ
wtimeoutmsZjournalfsync)r(   r   )r"   concernZwtimeoutjr6   r+   r+   r,   _parse_write_concernH   s
   



r9   r   c                 C  s   |  d}t|S )zParse read concern options.Zreadconcernlevel)r(   r   )r"   r7   r+   r+   r,   _parse_read_concernQ   s   
r:   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)r?   r@   rA   rB   )rC   rD   rE   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"   r;   Zuse_tlscertfileZ
passphraseca_certsZcrlfileZallow_invalid_certificatesZallow_invalid_hostnamesZdisable_ocsp_endpoint_checkZenabled_tls_optsoptctxr+   r+   r,   _parse_ssl_optionsW   sR   








rL   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.ZmaxpoolsizeZminpoolsizeZmaxidletimemsNz3minPoolSize must be smaller or equal to maxPoolSizeZconnecttimeoutmsZsockettimeoutmsZwaitqueuetimeoutmsevent_listenersappnamedriver
server_apiZcompressorsZzlibcompressionlevelr0   loadbalancedZmaxconnecting)max_connectingrP   load_balancedcredentialsr;   )r-   r(   r
   ZMAX_POOL_SIZEZMIN_POOL_SIZEZMAX_IDLE_TIME_SEC
ValueErrorZCONNECT_TIMEOUTZWAIT_QUEUE_TIMEOUTr   r   r   r   r   rL   ZMAX_CONNECTINGr   r   )r   r   r    r"   r;   rT   Zmax_pool_sizeZmin_pool_sizeZmax_idle_time_secondsconnect_timeoutsocket_timeoutZwait_queue_timeoutrM   rN   rO   rP   Zcompression_settingsssl_contextZtls_allow_invalid_hostnamesrS   rR   r+   r+   r,   _parse_pool_options   sL   




rY   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#   r;   r<   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 )NZdirectconnectionZlocalthresholdmsZserverselectiontimeoutmsZ
replicasetconnectZheartbeatfrequencymsZretrywritesZ
retryreadsserver_selectorauto_encryption_optsrQ   Z	timeoutmsZservermonitoringmode)!_ClientOptions__optionsr	   _ClientOptions__codec_optionsr(   !_ClientOptions__direct_connectionr
   ZLOCAL_THRESHOLD_MS"_ClientOptions__local_threshold_msZSERVER_SELECTION_TIMEOUT(_ClientOptions__server_selection_timeoutrY   _ClientOptions__pool_optionsr4   _ClientOptions__read_preference _ClientOptions__replica_set_namer9   _ClientOptions__write_concernr:   _ClientOptions__read_concern_ClientOptions__connectZHEARTBEAT_FREQUENCY#_ClientOptions__heartbeat_frequencyZRETRY_WRITES_ClientOptions__retry_writesZRETRY_READS_ClientOptions__retry_readsr   _ClientOptions__server_selector$_ClientOptions__auto_encryption_opts_ClientOptions__load_balanced_ClientOptions__timeoutZSERVER_MONITORING_MODE&_ClientOptions__server_monitoring_mode)selfr   r   r    r"   r;   r+   r+   r,   __init__   s.   




zClientOptions.__init__r$   c                 C     | j S )z7The original options used to create this ClientOptions.)r^   rq   r+   r+   r,   _options      zClientOptions._optionsOptional[bool]c                 C  rs   )z>Whether to begin discovering a MongoDB topology automatically.)rh   rt   r+   r+   r,   r[      rv   zClientOptions.connectr   c                 C  rs   )z5A :class:`~bson.codec_options.CodecOptions` instance.)r_   rt   r+   r+   r,   codec_options   rv   zClientOptions.codec_optionsc                 C  rs   )z:Whether to connect to the deployment in 'Single' topology.)r`   rt   r+   r+   r,   direct_connection   rv   zClientOptions.direct_connectionintc                 C  rs   )z&The local threshold for this instance.)ra   rt   r+   r+   r,   local_threshold_ms  rv   z ClientOptions.local_threshold_msc                 C  rs   )z:The server selection timeout for this instance in seconds.)rb   rt   r+   r+   r,   server_selection_timeout  rv   z&ClientOptions.server_selection_timeoutr   c                 C  rs   )N)rl   rt   r+   r+   r,   r\     s   zClientOptions.server_selectorc                 C  rs   )z$The monitoring frequency in seconds.)ri   rt   r+   r+   r,   heartbeat_frequency  rv   z!ClientOptions.heartbeat_frequencyr   c                 C  rs   )z.A :class:`~pymongo.pool.PoolOptions` instance.)rc   rt   r+   r+   r,   pool_options  rv   zClientOptions.pool_optionsr   c                 C  rs   )zA read preference instance.)rd   rt   r+   r+   r,   r.     rv   zClientOptions.read_preferencec                 C  rs   )zReplica set name or None.)re   rt   r+   r+   r,   replica_set_name   rv   zClientOptions.replica_set_namer   c                 C  rs   )z8A :class:`~pymongo.write_concern.WriteConcern` instance.)rf   rt   r+   r+   r,   write_concern%  rv   zClientOptions.write_concernr   c                 C  rs   )z6A :class:`~pymongo.read_concern.ReadConcern` instance.)rg   rt   r+   r+   r,   read_concern*  rv   zClientOptions.read_concernOptional[float]c                 C  rs   )z_The configured timeoutMS converted to seconds, or None.

        .. versionadded:: 4.2
        )ro   rt   r+   r+   r,   timeout/     zClientOptions.timeoutc                 C  rs   )z9If this instance should retry supported write operations.)rj   rt   r+   r+   r,   retry_writes7  rv   zClientOptions.retry_writesc                 C  rs   )z8If this instance should retry supported read operations.)rk   rt   r+   r+   r,   retry_reads<  rv   zClientOptions.retry_readsOptional[AutoEncryptionOpts]c                 C  rs   )z:A :class:`~pymongo.encryption.AutoEncryptionOpts` or None.)rm   rt   r+   r+   r,   r]   A  rv   z"ClientOptions.auto_encryption_optsc                 C  rs   )z@True if the client was configured to connect to a load balancer.)rn   rt   r+   r+   r,   rS   F  rv   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)rc   Z_event_listenersrM   rt   r+   r+   r,   rM   K  s   zClientOptions.event_listenersc                 C  rs   )zSThe configured serverMonitoringMode option.

        .. versionadded:: 4.5
        )rp   rt   r+   r+   r,   server_monitoring_modeV  r   z$ClientOptions.server_monitoring_modeN)T)
r   r   r   r   r    r!   r"   r#   r;   r<   )r$   r#   )r$   rw   )r$   r   )r$   rz   )r$   r   )r$   r   )r$   r   )r$   r!   )r$   r   )r$   r   )r$   r   )r$   r<   )r$   r   )r$   r   )r$   r   )__name__
__module____qualname____doc__rr   propertyru   r[   rx   ry   r{   r|   r\   r}   r~   r.   r   r   r   r   r   r   r]   rS   rM   r   r+   r+   r+   r,   rZ      sX    "
rZ   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#   r;   r<   r$   r=   )r   r   r   r   r    r!   r"   r#   r;   r<   r$   r   )4r   
__future__r   typingr   r   r   r   r   r   Zbson.codec_optionsr	   Zpymongor
   Zpymongo.compression_supportr   Zpymongo.errorsr   Zpymongo.monitoringr   r   Zpymongo.pool_optionsr   Zpymongo.read_concernr   Zpymongo.read_preferencesr   r   r   Zpymongo.server_selectorsr   Zpymongo.ssl_supportr   Zpymongo.write_concernr   r   r   r)   r   Zpymongo.encryption_optionsr   Zpymongo.pyopenssl_contextr   Zpymongo.topology_descriptionr   r-   r4   r9   r:   rL   rY   rZ   r+   r+   r+   r,   <module>   s6    



	

>0