+\hV>dZddlmZddlZddlZddlZddlmZmZm Z m Z m Z m Z m Z mZddlmZddlmZddlmZddlmZmZmZmZdd lmZmZdd lmZerdd lm Z d Z!e"e!Z#d Z$e"e$Z%dZ&e'gdZ(d&dZ)d'dZ* d(dZ+e&fd)dZ,hdZ-d*dZ.d+dZ/d+dZ0d+dZ1d,d-dZ2 d. d/dZ3e&fd0dZ4ejjdejldzd zZ7e'gd!Z8d1d"Z9 d2d#Z:e&ddddf d3d$Z;d4d%Z: @:zXUsername and password must be escaped according to RFC 3986, use urllib.parse.quote_plusz&The empty string is not valid username)countrNr partitionr )userinfouser_passwds rMparse_userinforZ}sq h(..-15Fx5P 4  ((-OD!V ABB  |F3 33rOc|jddk(r td|jd}|dk(r|dd|fS|d|||dzdfS)aValidates an IPv6 literal host:port string. Returns a 2-tuple of IPv6 literal followed by port where port is default_port if it wasn't specified in entity. :param entity: A string that represents an IPv6 literal enclosed in braces (e.g. '[::1]' or '[::1]:27017'). :param default_port: The port number to use when one wasn't specified in entity. ]zNan IPv6 address literal must be enclosed in '[' and ']' according to RFC 2732.z]:rSN)find ValueError)entity default_portrKs rMparse_ipv6_literal_hostrcsh{{32 \    DABwa|\)) !A;q1uw ''rOc@|}|}|ddk(rt||\}}n]|jdr||fS|jddk7r4|jddkDr t d|j dd\}}t |tr|jsBtd|Dr%|D] }|jst d |t d t|d kDst|dkr t d t|}|j|fS) aqValidates a host string Returns a 2-tuple of host followed by port where port is default_port if it wasn't specified in the string. :param entity: A host or host:port string where host could be a hostname or IP address. :param default_port: The port number to use when one wasn't specified in entity. r[.sockrRr]rSzReserved characters such as ':' must be escaped according RFC 2396. An IPv6 address literal must be enclosed in '[' and ']' according to RFC 2732.c3`K|]&}|jxs|j(ywN)isspaceisdigit).0cs rM zparse_host..s$tlsallowinvalidhostnamestlsallowinvalidcertificatestlsdisableocspendpointcheckcbt}|j|D]}|jd\}}|jdk(r"|j|gj |L||vrt j d|dd|jdk(r|}n t|}|||<|S)zHelper method for split_options which creates the options dict. Also handles the creation of a list for the URI tag_sets/ readpreferencetags portion, and the use of a unicode options string. =readpreferencetagszDuplicate URI option 'z'.r^ stacklevelauthmechanismproperties)rrort setdefaultappendwarningswarnr )optsdelimoptionsurioptkeyvaluevals rM_parse_optionsrs )*G**U# \\#& U 99;. .   sB ' . .u 5g~ 6se2>1Myy{77"5)GCL  NrOc~|jd}|?tD]6}||vsd}t||jd|j|fz|jd}|.d|vr!d}t|d|jdfz|durd|d<|jd}|+dD]&}|j|dusd}t||fzd |vrgd |vrcd d }||jd ||jd k7r0d }t||jd |jd fz|S)zRaise appropriate errors when conflicting TLS options are present in the options dictionary. :param options: Instance of _CaseInsensitiveDictionary containing MongoDB URI options. tlsinsecurez9URI options %s and %s cannot be specified simultaneously.ryrzT tlscrlfile)rryrzzDURI option %s=True cannot be specified when CRL checking is enabled.r7r8c<|dvr|dk(St|tr|S|S)N)truefalser)rpbool)rs rM truth_valuez-_handle_security_options..truth_value$s)''f}$#t$ JrOz=Can not specify conflicting values for URI options %s and %s.)rrreturnr)get_IMPLICIT_TLSINSECURE_OPTSr cased_key)rropterr_msgtlsallowinvalidcertsrrs rM_handle_security_optionsrs++m,K- Cg~U w00?ARARSVAWXX #;;'DE' (G 3QG0'2C2CDa2bcd  4 '59G1 2\*J` 3C{{34'` C6!122 3  EW,  w{{5) *k'++e:L.M MUGW(9(9%(@'BSBSTYBZ'[[\ \ NrOct|D]}|tvs t|\}}|dk(r|}||vrSd}tj||j ||j |fzt d|j |vd}tj||j ||fzt d|dk(sd}tj||j ||fzt d|S)a;Issue appropriate warnings when deprecated options are present in the options dictionary. Removes deprecated option key, value pairs if the options dictionary is found to also have the renamed option. :param options: Instance of _CaseInsensitiveDictionary containing MongoDB URI options. renamedz0Deprecated option '%s' ignored in favor of '%s'.r^r~z,Option '%s' is deprecated, use '%s' instead.removedzOption '%s' is deprecated. %s.)listrrrrDeprecationWarningpop)roptnamemodemessage newoptnamewarn_msgs rM_handle_option_deprecationsr2s= 1 17@MD'y $ (QHMM G$5$5g$>@Q@QR\@]#^^*#$ KK(I  1 1' :JGG&  ";  1 1' :GDD& -8 NrOc|jd}|tD]}|||< t|D]/}tj|d}||j |||<1|S)zNormalizes option names in the options dictionary by converting them to their internally-used names. :param options: Instance of _CaseInsensitiveDictionary containing MongoDB URI options. rN)rrrrr)rrrrintnames rM_normalize_optionsrYsw++m,K- 'C&GCL '=4.227DA  &{{73GG 4 NrOFct||S)aValidates and normalizes options passed in a MongoDB URI. Returns a new dictionary of validated and normalized options. If warn is False then errors will be thrown for invalid options, otherwise they will be ignored and a warning will be issued. :param opts: A dict of MongoDB URI options. :param warn: If ``True`` then warnings will be logged and invalid options will be ignored. Otherwise invalid options will cause errors. )r)rrs rMvalidate_optionsros !t ,,rOTc|jd}|jd} |dk\r|dk\r td|dk\r t|d}n9|dk\r t|d}n'|jddk7r t|d}ntt |}t |}|r t |}|r9ttt||}|jd d k(r td |S#t$r tddwxYw) aTakes the options portion of a MongoDB URI, validates each option and returns the options in a dictionary. :param opt: A string representing MongoDB URI options. :param validate: If ``True`` (the default), validate and normalize all options. :param warn: If ``False`` (the default), suppress all warnings raised during validation of options. :param normalize: If ``True`` (the default), renames all options to their internally-used names. &;rz-Can not mix '&' and ';' for option separatorsr|r]Nz'MongoDB URI options are key=value pairs authsourcez1the authSource database cannot be an empty string) r_rrr`rrrr rrr)rvalidater normalizeand_idxsemi_idxrs rM split_optionsr~siinGyy~H N a" u:>$%[\ \ ;;) *$%bc c ;;| $$%WX X % #rOc|siSt|ts tdi}|jD]\}}t|tstd|d|j ddt |}t |}t|}tt t|}t||\}}| td|r tddD]}||vrtd ||||<|S) z!Parse KMS TLS connection options.zkms_tls_options must be a dictzkms_tls_options["z"] must be a dictr8Tz!TLS is required for KMS providerszInsecure TLS options prohibited)r@r9r:r>z!Insecure TLS options prohibited: ) rpdict TypeErroritemsrrrrr rrr) kms_tls_optionsis_synccontextsproviderrr ssl_contextallow_invalid_hostnamesns rM_parse_kms_tls_optionsrs  ot ,899H,224-''4(/z9JKL L5$')'2'-!$'.0@0FG/A$/P, ,  $%HI I "$%FG G  -A Dy(+LQC)PQQ!,HX  --. OrOc|jtr d}|td}ng|jtr8t s"t j xsd}td|zd}|td}ntdtdtd|s tdd} d} d} d} t} |jd \}}}d |vr|jd \}}} n|}| rGt| } d | vr| jd d \} } tj| rtd | zd} |r| j!t#||||d|vr$|j%d\}}}t'|\} } n|}d |vrtd|zt|}d}|xs| j)d}|rm| j)drtdtdt+|d}t-|d k7rttd|d\}}|Lttd|s| j)d td|s |r tdt+||}t/|| || | | | | |dS)NFpythonzThe "dnspython" module must be installed to use mongodb+srv:// URIs. To fix this error install pymongo again: %s -m pip install pymongo>=4.3Tz)Invalid URI scheme: URI must begin with 'z' or ''z(Must provide at least one hostname or IP?/.rSzBad database name "%s"rQz;Any '/' in a unix domain socket must be percent-encoded: %sr5rz*Cannot specify directConnection=true with z URIs)rbz. URIs must include one, and only one, hostnamerz$ URIs must not include a port numberr6zDThe srvServiceName option is only allowed with 'mongodb+srv://' URIszAThe srvMaxHosts option is only allowed with 'mongodb+srv://' URIs)nodelistusernamepassworddatabase collectionrfqdn) startswithSCHEME SCHEME_LEN SRV_SCHEMEr sys executablerSRV_SCHEME_LENrrrUr ro _BAD_DB_CHARSsearchupdater rpartitionrZrrrIr)urirbrrr srv_max_hostsis_srv scheme_free python_pathrWrYdbaserrhost_plus_db_partrXr host_partrVrrrrvs rM _validate_urirs ~~f*+&  # ..4HK$15@A  ./* DVHFS]R^^_`aa CDD D F EJ(*G!,!6!6s!;q$ /99#> 1e%  U# %< % C 3 E:    &5=> > }T8T9EF i&11#6!U%h/ f e|VYbbcc  E D!?W[[%?M ;;) *$'QR\Q]]b%cd dE5 u:? |+YZ[ [1X d   |+OPQ Q  $45A R    O  E =5'"  rOci}tD].}|j|vs||||<|j|0|jD] \}}|||< |Srh) URI_OPTIONSrtrr)rcase_sensitiveoptionkvs rM_make_options_case_sensitiver^siN  <<>W $%,V_N6 " KK   1q rO)rJrqrr)rVrqrztuple[str, str])rarqrb Optional[int]rz%tuple[str, Optional[Union[str, int]]])rarqrbrrr)rrqrz Optional[str]rr)rrrr)F)rMapping[str, Any]rrrMutableMapping[str, Any])TFT) rrqrrrrrrrr)rrqrbrrzlist[_Address])rr rrrNone)rzOptional[Mapping[str, Any]]rrrzdict[str, SSLContext])rrqrbrrrrrrrrrrdict[str, Any])rrrr)=__doc__ __future__rrerrtypingrrrrrr r r urllib.parser !pymongo.asynchronous.srv_resolverr pymongo.client_optionsrpymongo.commonrrrrpymongo.errorsrrpymongo.typingsrpymongo.pyopenssl_contextrrrIrrr DEFAULT_PORT frozensetrrNrZrcrwrrrrrrrrcompileescaper_ALLOWED_TXT_OPTSrrrrrOrMr s #    &=5 :$4  [  Z /1 h  40( (,(*(.;G0h,2j$N, - MQ* **,0*EI**Z;G4 37!33c9: \ Y!0! !!L#/#' ] ]]]  ]  ] ! ]]@rO