o
    C©ÌhL2  ã                   @  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r‚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, d3dd„Z-d4d d!„Z.d5d#d$„Z/d6d&d'„Z0d7d+d,„Z1d8d.d/„Z2G d0d1„ d1ƒZ3d2S )9z†Tools 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.   úe/var/www/html/Moveonwheels/move_on_wheels/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.connectúCodecOptions[Any]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 )zŒThe 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