a cCU @sPddlZddlmZmZmZmZmZmZmZm Z ddl m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZddlmZddlmZmZddlm Z m!Z!e rddl"a"ddl#m$Z$dd l%m&Z&dd l'm(Z(dd l m)Z)ee)ddfZ*Gd d d e$ddZ+Gddde$ddZ,nda"Gdd d e-Z+ee.e/e0eee.e/e0fee.e0fffZ1gdZ2da3da4da5da6da7dZ8dZ9dZ:dZ;dZee.dddZ?ee.ddd Z@ee.dd!d"ZAee.dd#d$ZBGd%d&d&e.ZCGd'd(d(eCZDGd)d*d*eDZEGd+d,d,eCZFGd-d.d.eCZGGd/d0d0eGZHGd1d2d2eCZIGd3d4d4eCZJGd5d6d6eCZKGd7d8d8eCZLGd9d:d:eCZMd;ddd?d@ZOdddAdBZPGdCdDdDe.ZQGdEdFdFeZRGdGdHdHeZSGdIdJdJeZTGdKdLdLe ZUeVdMZWee.ee.e.fdNdOdPZXdS)QN) IPv4Address IPv4Interface IPv4Network IPv6Address IPv6Interface IPv6Network _BaseAddress _BaseNetwork) TYPE_CHECKINGAny CollectionDict GeneratorListMatchOptionalPatternSetTupleTypeUnioncast no_type_check)errors)Representationupdate_not_none)constr_length_validator str_validator) TypedDict) BaseConfig) ModelField) AnyCallablec@seZdZUeed<eeed<eeed<eeed<eeed<eeed<eeed<eeed<eeed <eeed <d S) Partsschemeuserpasswordipv4ipv6domainportpathqueryfragmentN)__name__ __module__ __qualname__str__annotations__rr3r3^/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/pydantic/networks.pyr#,s         r#F)totalc@sBeZdZUeed<eeed<eeed<eeed<eed<dS) HostPartshosttld host_typer*rebuildN)r.r/r0r1r2rboolr3r3r3r4r68s    r6c@s eZdZdS)r#N)r.r/r0r3r3r3r4r#Bs)AnyUrl AnyHttpUrlFileUrlHttpUrl stricturlEmailStr NameEmail IPvAnyAddressIPvAnyInterface IPvAnyNetwork PostgresDsn CockroachDsnAmqpDsnRedisDsnMongoDsnKafkaDsnvalidate_emailz(?:(?P(?:\d{1,3}\.){3}\d{1,3})(?=$|[/:#?])|(?P\[[A-F0-9]*:[A-F0-9:]+\])(?=$|[/:#?])|(?P[^\s/:?#]+))?(?::(?P\d+))?z&(?:(?P[a-z][a-z0-9+\-.]+)://)?z3(?:(?P[^\s:/]*)(?::(?P[^\s/]*))?@)?z(?P/[^\s?#]*)?z(?:\?(?P[^\s#]*))?z(?:#(?P[^\s#]*))?returncCs2tdur.ttttttttj atSN) _url_regex_cacherecompile _scheme_regex_user_info_regex _host_regex _path_regex _query_regex_fragment_regex IGNORECASEr3r3r3r4 url_regexqs rZcCs0tdur,tttdttttjatS)z Compiled multi host url regex. Additionally to `url_regex` it allows to match multiple hosts. E.g. host1.db.net,host2.db.net Nz(?P([^/]*))) _multi_host_url_regex_cacherQrRrSrTrVrWrXrYr3r3r3r4multi_host_url_regex{s r\cCs2tdur.d}d}td|d||tjatS)Nz'[_0-9a-z](?:[-_0-9a-z]{0,61}[_0-9a-z])?z(?P\.[a-z]{2,63})?\.?(?:\.)*?)_ascii_domain_regex_cacherQrRrY)Z ascii_chunkZascii_domain_endingr3r3r4ascii_domain_regexsr`cCs2tdur.d}d}td|d||tjatS)NzB[_0-9a-\U00040000](?:[-_0-9a-\U00040000]{0,61}[_0-9a-\U00040000])?z<(?P(\.[^\W\d_]{2,63})|(\.(?:xn--)[_0-9a-z-]{2,63}))?\.?r]r^)_int_domain_regex_cacherQrRrY)Z int_chunkZint_domain_endingr3r3r4int_domain_regexs rbcCstdurtttjatSrO)_host_regex_cacherQrRrUrYr3r3r3r4 host_regexs rdcs6eZdZUdZdZdZdZeee e d<dZ e e d<dZ e e d<dZe e d <eZee e d <d Zeee ed d dZdddddddddd e e ee ee ee ee e ee ee ee ee dd ddZeddddddde ee ee e ee ee ee ee e e d ddZeee efddddZeddddZeedd dd!d"d#Zeee e d$dd%d&d'Ze e eee d d(d)Z!e ee dd*d+d,Z"ed9d$e d$d-d.d/Z#ed$e$e ee e e fd0d1d2Z%e d$d$d0d3d4Z&ed$d$d0d5d6Z'e dfd7d8 Z(Z)S):r<TrNallowed_schemesF tld_required user_required host_required hidden_parts r$r%r&r7r8r9r*r+r,r-urlrNcKs$t||dur|jfi|n|SrO)r1__new__build)clsrmkwargsr3r3r4rnszAnyUrl.__new__r)) r%r&r7r8r9r*r+r,r-) rmr$r%r&r7r8r9r*r+r,r-rNc CsJt|||_||_||_||_||_||_||_| |_ | |_ | |_ dSrO) r1__init__r$r%r&r7r8r9r*r+r,r-) selfrmr$r%r&r7r8r9r*r+r,r-r3r3r4rrs zAnyUrl.__init__)r%r&r*r+r,r-) r$r%r&r7r*r+r,r-_kwargsrNc Kstf||||||||d| } |d} |r4| |7} |rD| d|7} |sL|rT| d7} | |7} |rd|jvs~|| d|kr| d|7} |r| |7} |r| d|7} |r| d|7} | S)N)r$r%r&r7r*r+r,r-z://:@r*?#)r#rjget_default_partsget) rpr$r%r&r7r*r+r,r-rtpartsrmr3r3r4ros:   "   z AnyUrl.build field_schemarNcCst||j|jdddS)Nuri)Z minLengthZ maxLengthformat)r min_length max_lengthrpr}r3r3r4__modify_schema__szAnyUrl.__modify_schema__CallableGeneratorrMccs |jVdSrOvalidaterpr3r3r4__get_validators__szAnyUrl.__get_validators__r!r )valuefieldconfigrNcCs|j|kr|St|}|jr$|}ttt|||}||}|sLJdtd|}| |}| |}| t |krt j|| dd||||S)NzURL regex failed unexpectedlyr#)extra) __class__rstrip_whitespacestriprr1r _match_url groupdictapply_default_partsvalidate_partsendlenrZ UrlExtraError _build_url)rprrrrmmZoriginal_partsr{r3r3r4r s     zAnyUrl.validater#rrmr{rNc CsT||\}}}}||rdn||d|d|d||||d|d|d|dd S) z Validate hosts and build the AnyUrl object. Split from `validate` so this method can be altered in `MultiHostDsn`. Nr$r%r&r*r+r,r-rk) validate_host)rprrmr{r7r8r9r:r3r3r4r s zAnyUrl._build_urlcCs t|SrO)rZmatchrmr3r3r4r6szAnyUrl._match_url)r*rNcCs |durt|dkrtdS)Ni)intrZ UrlPortError)r*r3r3r4_validate_port:szAnyUrl._validate_portr{ validate_portrNcCsp|d}|durt|jr<||jvrtn|dkrd}t|}|durt|}|dur~td}|d}|dur|st|}|dusJ|d}d}|dur|dd}n|jrt|rd}d}| d  d }|dur| d  d }||||fS) N)NNF)r)r'r(r)FTr8rZ int_domainidnaascii) rirZ UrlHostErrorr` fullmatchrbgrouprgZUrlHostTldErrorencodedecode) rpr{r8r9r:fr7Zis_internationaldr3r3r4rUsD           zAnyUrl.validate_hostcCsiSrOr3r{r3r3r4ryszAnyUrl.get_default_partscCs,||D]\}}||s|||<q|SrO)ryitems)rpr{keyrr3r3r4rs zAnyUrl.apply_default_partscs:dfddjD}jjdtd|dS)Nz, c3s0|](}t|dur|dt|VqdS)N=)getattr).0nrsr3r4 z"AnyUrl.__repr__..())join __slots__rr.super__repr__)rsrrrr4rszAnyUrl.__repr__)T)*r.r/r0rrrrfrr r1r2rgr;rhrirrjrrrobjectrnrr classmethodror r rrrrr staticmethodrrrrrryrr __classcell__r3r3rr4r<s     +")r<c@seZdZddhZdZdS)r=httphttpsr3N)r.r/r0rfrr3r3r3r4r=sr=c@s.eZdZdZdZdhZedddddZdS) r?Ti#r*r#rcCsd|ddkrdndiS)Nr*r$r80443r3rr3r3r4ryszHttpUrl.get_default_partsN)r.r/r0rgrrjrryr3r3r3r4r?s r?c@seZdZdhZdZdZdS)r>fileFr3N)r.r/r0rfrirr3r3r3r4r>sr>cseZdZejdZddeeededfddZe e ee e ddd Z e dd ed d fd d Ze e e e d ddddZZS) MultiHostDsn)hostsNr6)argsrrqcstj|i|||_dSrO)rrrr)rsrrrqrr3r4rrszMultiHostDsn.__init__rlcCs t|SrO)r\rrr3r3r4rszMultiHostDsn._match_urlTr#rcstj|ddS)NF)r)rr)rpr{rrr3r4rszMultiHostDsn.validate_partsrc Cs g}t}|ddD]N}||}||\}}} } |d} || ||| || | dqt|dkr|t dd|Drdn||d|d |d |d |d |d d|d S|d} || drdn||d|d |d | d| d| d| d|d |d |d d SdS)Nr,r*)r7r9r8r:r*rcSsg|] }|dqS)r:r3)rhpr3r3r4 rz+MultiHostDsn._build_url..r$r%r&r+r,r-)r$r%r&r+r,r-r9rrr:r7r8r9rk) rdrsplitrrrzrappendrany) rprrmr{Z hosts_partsZhost_rer7rr8r9r:r*Z host_partr3r3r4rsR    zMultiHostDsn._build_url)T)r.r/r0r<rr rrrrrr1rrrr;rrrr3r3rr4rs $rc@seZdZhdZdZdZdS)rF> zpostgresql+pygresqlZpostgresZ postgresqlzpostgresql+psycopgzpostgresql+pg8000zpostgresql+psycopg2cffizpostgresql+py-postgresqlzpostgresql+psycopg2zpostgresql+asyncpgTr3N)r.r/r0rfrhrr3r3r3r4rFs rFc@seZdZhdZdZdS)rG>Z cockroachdbzcockroachdb+psycopg2zcockroachdb+asyncpgTN)r.r/r0rfrhr3r3r3r4rGsrGc@seZdZddhZdZdS)rHZamqpZamqpsFN)r.r/r0rfrir3r3r3r4rHsrHc@s0eZdZdZddhZdZedddddZd S) rIr3ZredisZredissFr#rcCs |ds|dsdnddddS)Nr'r( localhostZ6379z/0)r)r*r+r3rr3r3r4ry szRedisDsn.get_default_partsN)r.r/r0rrfrirryr3r3r3r4rIs rIc@s&eZdZdhZedddddZdS)rJZmongodbr#rcCsddiS)Nr*Z27017r3rr3r3r4ryszMongoDsn.get_default_partsNr.r/r0rfrryr3r3r3r4rJsrJc@s&eZdZdhZedddddZdS)rKZkafkar#rcCs dddS)NrZ9092)r)r*r3rr3r3r4ry"szKafkaDsn.get_default_partsNrr3r3r3r4rKsrKTrerrrrgrirf)rrrrgrirfrNcCs"t||||||d}tdtf|S)NrZUrlValue)dicttyper<)rrrrgrirf namespacer3r3r4r@*s r@c Cs@z ddlaWn.ty:}ztd|WYd}~n d}~00dS)NrzCemail-validator is not installed, run `pip install pydantic[email]`)email_validator ImportError)er3r3r4import_email_validator?s rc@sReZdZeeeefddddZeddddZee eed d d Z dS) rANr|cCs|jddddS)Nstringemailrrupdaterr3r3r4rHszEmailStr.__modify_schema__rrMccsttV|jVdSrO)rrrrr3r3r4rLszEmailStr.__get_validators__rrNcCs t|dS)Nr)rLrprr3r3r4rTszEmailStr.validate) r.r/r0rr r1r rrrrr3r3r3r4rAGs rAc@seZdZdZeedddZeedddZe e eefddd d Z e d d d dZ e eddddZ ed ddZdS)rBnamercCs||_||_dSrOr)rsrrr3r3r4rr\szNameEmail.__init__)otherrNcCs"t|to |j|jf|j|jfkSrO) isinstancerBrr)rsrr3r3r4__eq__`szNameEmail.__eq__Nr|cCs|jddddS)Nrz name-emailrrrr3r3r4rcszNameEmail.__modify_schema__rrMccst|jVdSrO)rrrr3r3r4rgszNameEmail.__get_validators__rcCs"|j|kr|St|}|t|SrO)rrrLrr3r3r4rms zNameEmail.validatecCs|jd|jdS)Nz <>rrr3r3r4__str__tszNameEmail.__str__)r.r/r0rr1rrr r;rrr rrrrr3r3r3r4rBYsrBc@sdeZdZdZeeeefddddZedddd Z ee ee e fe e efd d d ZdS) rCr3Nr|cCs|jddddS)NrZ ipvanyaddressrrrr3r3r4r{szIPvAnyAddress.__modify_schema__rrMccs |jVdSrOrrr3r3r4rsz IPvAnyAddress.__get_validators__rcCsHz t|WStyYn0z t|WStyBtYn0dSrO)r ValueErrorrrZIPvAnyAddressErrorrr3r3r4rs    zIPvAnyAddress.validate)r.r/r0rrr r1r rrrbytesrrrrr3r3r3r4rCxsrCc@sZeZdZdZeeeefddddZedddd Z ee e e e fd d d ZdS) rDr3Nr|cCs|jddddS)NrZipvanyinterfacerrrr3r3r4rsz!IPvAnyInterface.__modify_schema__rrMccs |jVdSrOrrr3r3r4rsz"IPvAnyInterface.__get_validators__rcCsHz t|WStyYn0z t|WStyBtYn0dSrO)rrrrZIPvAnyInterfaceErrorrr3r3r4rs    zIPvAnyInterface.validate)r.r/r0rrr r1r rr NetworkTyperrrrr3r3r3r4rDsrDc@sVeZdZeeeefddddZeddddZee e e e fd d d Z dS) rENr|cCs|jddddS)NrZ ipvanynetworkrrrr3r3r4rszIPvAnyNetwork.__modify_schema__rrMccs |jVdSrOrrr3r3r4rsz IPvAnyNetwork.__get_validators__rcCsHz t|WStyYn0z t|WStyBtYn0dSrO)rrrrZIPvAnyNetworkErrorrr3r3r4rs    zIPvAnyNetwork.validate)r.r/r0rr r1r rrrrrrrr3r3r3r4rEs rEz([\w ]*?) *<(.*)> *rc Cstdurtt|}d}|r,|\}}|}ztj|ddWn0tjyv}zt |WYd}~n d}~00| d}|d|}||d }|p|||fS)aS Brutally simple email address validation. Note unlike most email address validation * raw ip address (literal) domain parts are not allowed. * "John Doe " style "pretty" email addresses are processed * the local part check is extremely basic. This raises the possibility of unicode spoofing, but no better solution is really possible. * spaces are striped from the beginning and end of addresses but no error is raised See RFC 5322 but treat it with suspicion, there seems to exist no universally acknowledged test for a valid email! NF)Zcheck_deliverabilityrv) rrpretty_email_regexrgroupsrrLZEmailNotValidErrorrZ EmailErrorindexr)rrrrrZat_indexZ local_partZ global_partr3r3r4rLs      rL)YrQ ipaddressrrrrrrrr typingr r r r rrrrrrrrrrrrrutilsrrZ validatorsrrrZtyping_extensionsrrr fieldsr!r"rr#r6rr1rrr__all__rPr[r_rarcrUrSrTrVrWrXrZr\r`rbrdr<r=r?r>rrFrGrHrIrJrKr;r@rrArBrCrDrErRrrLr3r3r3r4s( D      *    e @