o Sb+@sdZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZdd lmZdd lmZdd lmZmZdd lmZddlmZddlmZddZddZddZ ddZ!ddZ"ddZ#Gddde$Z%dS)z$Tools to parse mongo client options.)Optional)_parse_codec_options)common)_build_credentials_tuple)validate_boolean)CompressionSettings)ConfigurationError)_EventListeners) PoolOptions) ReadConcern)make_read_preferenceread_pref_mode_from_name)any_server_selector)get_ssl_context) WriteConcerncCs<|d|rdnd}|d}|s|rt||||||SdS)z!Parse authentication credentials.Z authmechanismDEFAULTNZ authsource)getr)usernamepassworddatabaseoptionsZ mechanismsourcer=/tmp/pip-target-onvjaxws/lib/python/pymongo/client_options.py_parse_credentials"s  rcCsFd|vr|dS|dd}t|}|d}|dd}t|||S)zParse read preference options.read_preferenceZreadpreferenceprimaryZreadpreferencetagsZmaxstalenessseconds)rr r )rnamemodetagsZ max_stalenessrrr_parse_read_preference+s    r!cCs6|d}|d}|d}|d}t||||S)zParse write concern options.wZ wtimeoutmsZjournalfsync)rr)rconcernZwtimeoutjr#rrr_parse_write_concern7s    r&cCs|d}t|S)zParse read concern options.Zreadconcernlevel)rr )rr$rrr_parse_read_concern@s r'c Cs|d}|durtd||d}|d}|d}|d}|dd}|d d}|d d}g} d D]} | |vrG|| rG| | q8d D]} | |vrY|| sY| | qJ| rn|durcd }n |sntdd| |r~t|||||||} | |fSd|fS)zParse ssl options.ZtlsNtlscertificatekeyfiletlscertificatekeyfilepassword tlscafile tlscrlfiletlsallowinvalidcertificatesFtlsallowinvalidhostnamestlsdisableocspendpointcheck)r(r)r*r+)r,r-r.TzmTLS has not been enabled but the following tls parameters have been set: %s. Please set `tls=True` or remove.z, )rrappendrjoinr) rZuse_tlscertfileZ passphraseca_certsZcrlfileZallow_invalid_certificatesZallow_invalid_hostnamesZdisable_ocsp_endpoint_checkZenabled_tls_optsoptctxrrr_parse_ssl_optionsFsP            r5cCst||||}|dtj}|dtj}|dtj}|dur(||kr(td|dtj}|d} |dtj} |d } |d } |d } |d }t |d g|dd}t |\}}|d}|dtj }t ||||| | ||t | | | |||||dS)zParse connection pool options.Z maxpoolsizeZ minpoolsizeZ maxidletimemsNz3minPoolSize must be smaller or equal to maxPoolSizeZconnecttimeoutmsZsockettimeoutmsZwaitqueuetimeoutmsevent_listenersappnamedriver server_apiZ compressorsZzlibcompressionlevelr loadbalancedZ maxconnecting)max_connectingr9 load_balanced credentials)rrrZ MAX_POOL_SIZEZ MIN_POOL_SIZEZMAX_IDLE_TIME_SEC ValueErrorZCONNECT_TIMEOUTZWAIT_QUEUE_TIMEOUTrr5ZMAX_CONNECTINGr r )rrrrr=Z max_pool_sizeZ min_pool_sizeZmax_idle_time_secondsconnect_timeoutsocket_timeoutZwait_queue_timeoutr6r7r8r9Zcompression_settings ssl_contextZtls_allow_invalid_hostnamesr<r;rrr_parse_pool_optionssJ       rBc@seZdZdZddZeddZeddZedd Zed d Z ed d Z eddZ eddZ eddZ eddZeddZeddZeddZeddZedeefdd Zed!d"Zed#d$Zed%d&Zed'd(Zed)d*Zd+S), ClientOptionszRead only configuration options for a MongoClient. Should not be instantiated directly by application developers. Access a client's options via :attr:`pymongo.mongo_client.MongoClient.options` instead. cCs||_t||_|d|_|dtj|_|dtj|_ t |||||_ t ||_ |d|_t||_t||_|d|_|dtj|_|dtj|_|dtj|_|d t|_|d |_|d |_|d |_dS) NZdirectconnectionZlocalthresholdmsZserverselectiontimeoutmsZ replicasetconnectZheartbeatfrequencymsZ retrywritesZ retryreadsserver_selectorauto_encryption_optsr:Z timeoutms)_ClientOptions__optionsr_ClientOptions__codec_optionsr!_ClientOptions__direct_connectionrZLOCAL_THRESHOLD_MS"_ClientOptions__local_threshold_msZSERVER_SELECTION_TIMEOUT(_ClientOptions__server_selection_timeoutrB_ClientOptions__pool_optionsr!_ClientOptions__read_preference _ClientOptions__replica_set_namer&_ClientOptions__write_concernr'_ClientOptions__read_concern_ClientOptions__connectZHEARTBEAT_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__timeout)selfrrrrrrr__init__s(         zClientOptions.__init__cC|jS)z7The original options used to create this ClientOptions.)rGrYrrr_optionszClientOptions._optionscCr[)z>Whether to begin discovering a MongoDB topology automatically.)rQr\rrrrDr^zClientOptions.connectcCr[)z5A :class:`~bson.codec_options.CodecOptions` instance.)rHr\rrr codec_optionsr^zClientOptions.codec_optionscCr[)z:Whether to connect to the deployment in 'Single' topology.)rIr\rrrdirect_connectionr^zClientOptions.direct_connectioncCr[)z&The local threshold for this instance.)rJr\rrrlocal_threshold_msr^z ClientOptions.local_threshold_mscCr[)z:The server selection timeout for this instance in seconds.)rKr\rrrserver_selection_timeoutr^z&ClientOptions.server_selection_timeoutcCr[)N)rUr\rrrrEszClientOptions.server_selectorcCr[)z$The monitoring frequency in seconds.)rRr\rrrheartbeat_frequencyr^z!ClientOptions.heartbeat_frequencycCr[)z.A :class:`~pymongo.pool.PoolOptions` instance.)rLr\rrr pool_optionsr^zClientOptions.pool_optionscCr[)zA read preference instance.)rMr\rrrrr^zClientOptions.read_preferencecCr[)zReplica set name or None.)rNr\rrrreplica_set_namer^zClientOptions.replica_set_namecCr[)z8A :class:`~pymongo.write_concern.WriteConcern` instance.)rOr\rrr write_concernr^zClientOptions.write_concerncCr[)z6A :class:`~pymongo.read_concern.ReadConcern` instance.)rPr\rrr read_concernr^zClientOptions.read_concernreturncCr[)z]The configured timeoutMS converted to seconds, or None. ..versionadded: 4.2 )rXr\rrrtimeout szClientOptions.timeoutcCr[)z9If this instance should retry supported write operations.)rSr\rrr retry_writesr^zClientOptions.retry_writescCr[)z8If this instance should retry supported read operations.)rTr\rrr retry_readsr^zClientOptions.retry_readscCr[)z:A :class:`~pymongo.encryption.AutoEncryptionOpts` or None.)rVr\rrrrFr^z"ClientOptions.auto_encryption_optscCr[)z@True if the client was configured to connect to a load balancer.)rWr\rrrr<!r^zClientOptions.load_balancedcCs |jjS)zThe event listeners registered for this client. See :mod:`~pymongo.monitoring` for details. .. versionadded:: 4.0 )rLZ_event_listenersr6r\rrrr6&s zClientOptions.event_listenersN)__name__ __module__ __qualname____doc__rZpropertyr]rDr_r`rarbrErcrdrrerfrgrfloatrirjrkrFr<r6rrrrrCsR                 rCN)&rotypingrZbson.codec_optionsrZpymongorZ pymongo.authrZpymongo.commonrZpymongo.compression_supportrZpymongo.errorsrZpymongo.monitoringr Z pymongo.poolr Zpymongo.read_concernr Zpymongo.read_preferencesr r Zpymongo.server_selectorsrZpymongo.ssl_supportrZpymongo.write_concernrrr!r&r'r5rBobjectrCrrrrs,                ;)