LfNddlZddlZddlZddlmZmZddlmZddlm Z m Z m Z m Z m Z mZddlZddlmZmZddlmZmZdd dd d ZeZd ed efd ZGddZeGddZdZdZej<edaej<eda edZ!edZ"eeeddZ#y)N)MappingSequence) ip_address) SplitResult parse_qslquoteurljoinurlsplit urlunsplit) MultiDictMultiDictProxy)_Quoter _UnquoterPi)httphttpswswssobjreturncd|_|S)Nyarl) __module__)rs +/usr/lib/python3/dist-packages/yarl/_url.pyrewrite_modulersCN Jc&eZdZdZdZefdZdZy)cached_propertyaRUse as a class method decorator. It operates almost exactly like the Python `@property` decorator, but it puts the result of the method it decorates into the instance dict after the first call, effectively replacing the function it decorates with an instance variable. It is, in Python parlance, a data descriptor. c||_ |j|_|j|_y#t$r d|_Y$wxYw)N)wrapped__doc__AttributeError__name__name)selfr"s r__init__zcached_property.__init__ s@  "??DL$$  DL s ,??c||S|jj|j|}||ur|S|j|}||j|j<|SN)_cachegetr&r")r'instowner _sentinelvals r__get__zcached_property.__get__(sV <Kkkoodii3 i Jll4 !$ DII rctd)Nzcached property is read-only)r$)r'r-values r__set__zcached_property.__set__2s;<Ze,dAZ?e,dBZ@e,dCZAe,dDZBe,dEZCe,dFZDe,dGZEe,dHZFe,dIZGeHdJZIedKZJed`dLZKe dadMZLdNZMdOZNdPZOdQZPdRZQddSdTZRedUZSeHdVZTdWZUdXZVdYZWdZZXd[ZYd\ZZd]Z[d^Z\y)bURL)r+_valF)requotez@:z/+)safe protectedr;)r<r=z?/:@z=+&;T)r<r=qsr;)r<r=r>)r<r>r;)r<r;)r<+)unsafe)r>r!N)encodedstrictcJ|tjdt||ur|St|tur t |}nNt|t ur |s;t dt|trt t|}n td|s|dsd}d}nQ|j}| t d |j}|j|j|j||dd }|j|d }|r|j|}|j!|| |j#|d } |j%|d } t |d||| | }t&j)|} || _i| _| S#t $r}t d|d}~wwxYw)Nzstrict parameter is ignoredz$Cannot apply decoding to SplitResultz#Constructor parameter should be strrr!z/Invalid URL: host is required for absolute urlsz/Invalid URL: port can't be converted to integerT)encoder;hostpathr)warningswarntypestrr r ValueError isinstance TypeErrorhostnameport _make_netlocusernamepassword_PATH_REQUOTER_normalize_path _validate_authority_uri_abs_path_QUERY_REQUOTER_FRAGMENT_REQUOTERobject__new__r:r+) clsr0rArBnetlocrGrSerHqueryfragmentr's rr]z URL.__new__s   MM7 8 9 J 9 3-C #Y+ % !GHH S !3s8$CAB Bq6||<$%VWW88D ))LL#,,d4QU*%%c!f-D**40  0 0d 0 F''A/E--c!f5Hc!ffdE8DC~~c"   )"$Is8 F F" FF") scheme authorityuserrVrGrSrHra query_stringrbrAc |r|s|s|s|r td|r |s td|r | r td|||| | td|rS| r|} nrtd|ddd} |j| j| j | j | jd} n$|s |s|s|sd} n|j||||| | } | sY|j|}| r|j|}|j|| |j| } |j| } |t|| || | d }|r|j|S|S) zCreates and returns a new URLz@Can't mix "authority" with "user", "password", "host" or "port".z/Can't build URL with "port" but without "host".z6Only one of "query" or "query_string" should be passedzuNoneType is illegal for "scheme", "authority", "path", "query_string", and "fragment" args, use empty string instead.r!T)rD)rD encode_hostrFrA)rOrQrrTrUrVrRrS _PATH_QUOTERrXrY _QUERY_QUOTER_FRAGMENT_QUOTER with_query)r^rcrdrerVrGrSrHrarfrbrAr_tmpurls rbuildz URL.builds$ $(ddS  OP P \UV V N |#Q  "!"iR<))LL#,, chht*htDF%%hdw;PWK&F##D)D**40  0 0d 0 F,,\:L++H5H lH Et  >>%( (Jrc td|d)NzInheriting a class z from URL is forbidden)rQ)r^s r__init_subclass__zURL.__init_subclass__s-cW4JKLLrc|j}|js:|jr*|js |jr|j d}t |SN/rH)r:rH is_absoluterarb_replacer r'r0s r__str__z URL.__str__sCiixxD,,.CII,,C,(C#rcL|jjdt|dS)Nz('z')) __class__r%rNr's r__repr__z URL.__repr__ s$..))*"SYKr::rc6t|jdS)Nascii)rNrDr}s r __bytes__z URL.__bytes__s4y((rc"t|turtS|j}|js"|j r|j d}|j}|js"|j r|j d}||k(Srt)rMr9NotImplementedr:rHrwrx)r'otherval1val2s r__eq__z URL.__eq__stE{c!! !yyyyT--/==c=*DzzyyU..0==c=*Dt|rc|jjd}|T|j}|js"|j r|j d}t |x}|jd<|S)Nhashrurv)r+r,r:rHrwrxr)r'retr0s r__hash__z URL.__hash__ s`kkoof% ;))C88 0 0 2lll,(,S 1C$++f% rcbt|turtS|j|jkSr*rMr9rr:r'rs r__le__z URL.__le__)'E{c!! !yyEJJ&&rcbt|turtS|j|jkSr*rrs r__lt__z URL.__lt__.'E{c!! !yy5::%%rcbt|turtS|j|jk\Sr*rrs r__ge__z URL.__ge__3rrcbt|turtS|j|jkDSr*rrs r__gt__z URL.__gt__8rrc|j|}|jdrtd|d|jj}|dk(rd|z}nW|s|j s|}nB|j djd}|j|dj|}|j r|j|}t|jj|dddS)NruzAppending path z! starting from slash is forbiddenr!rHrarbTri) rj startswithrOr:rHrwrstripsplitappendjoinrXr9rx)r'r&rHnew_pathpartss r __truediv__zURL.__truediv__=s  & ??3 !$)JK yy~~ 3;TzHd..0HKK$**3/E LL xxH    ++H5H II  HB  Dd  rc$|j|Sr*) update_query)r'ras r__mod__z URL.__mod__Rs  ''rrct|jjxsF|jjxs.|jjxs|jj Sr*)boolr:r_rHrarbr}s r__bool__z URL.__bool__UsE II   W  W$))// WTYYEWEW  rc|jfSr*)r:r}s r __getstate__zURL.__getstate__Zs |rc~|d(t|dtr|dd|_i|_y|^|_}i|_y)Nrrr:)rPdictr:r+)r'stateunuseds r __setstate__zURL.__setstate__]sG 8  58T :a(DI "' DI rc|jduS)zA check for absolute URLs. Return True for absolute ones (having scheme or starting with //), False otherwise. N)raw_hostr}s rrwzURL.is_absolutees}}D((rc~|jytj|j}|y|j|k(S)zA check for default port. Return True if port is default for specified scheme, e.g. 'http://python.org' or 'http://python.org:80', False otherwise. F)rS DEFAULT_PORTSr,rc)r'defaults ris_default_portzURL.is_default_portns< 99 ##DKK0 ?yyG##rc&|js td|jjs td|j}|j dd|j |j }|j|ddd}t|dS)z}Return an URL with scheme, host and port parts only. user, password, path, query and fragment are removed. URL should be absolutezURL should have schemeNr!)r_rHrarbTri) rwrOr:rcrTrRrSrxr9)r'vr_r0s roriginz URL.origin}s!56 6yy56 6 II""4qzz166BjjRrBjG3%%rc|js td|jjdd}t |dS)zhReturn a relative part of the URL. scheme, user, password, host and port are removed. rr!)rcr_Tri)rwrOr:rxr9rys rrelativez URL.relativesB !56 6ii  2 63%%rc.|jjS)zdScheme for absolute URLs. Empty string for relative URLs or URLs starting with // )r:rcr}s rrcz URL.schemeyyrc.|jjS)zQEncoded authority part of URL. Empty string for relative URLs. )r:r_r}s r raw_authorityzURL.raw_authorityrrc~|j|j|j|j|jdS)zQDecoded authority part of URL. Empty string for relative URLs. Frh)rTrerVrGrSr}s rrdz URL.authoritys7  IIt}}dii!  rc8|jj}|sy|S)zEEncoded user part of URL. None if user is missing. N)r:rUr'rs rraw_userz URL.raw_usersii   rc8|j|jS)zEDecoded user part of URL. None if user is missing. ) _UNQUOTERrr}s rrezURL.users~~dmm,,rc.|jjS)zMEncoded password part of URL. None if password is missing. )r:rVr}s r raw_passwordzURL.raw_passwordyy!!!rc8|j|jS)zMDecoded password part of URL. None if password is missing. )rrr}s rrVz URL.password~~d//00rc.|jjS)zDEncoded host part of URL. None for relative URLs. )r:rRr}s rrz URL.raw_hostsyy!!!rcB|j}|yd|vr|St|S)zDDecoded host part of URL. None for relative URLs. N%)r _idna_decode)r'raws rrGzURL.hosts.mm ; #:JC  rc|jjxs)tj|jjS)zPort part of URL, with scheme-based fallback. None for relative URLs or URLs without explicit port and scheme without default port substitution. )r:rSrr,rcr}s rrSzURL.ports,yy~~D!2!24993C3C!DDrc.|jjS)zyPort part of URL, without scheme-based fallback. None for relative URLs or URLs without explicit port. )r:rSr}s r explicit_portzURL.explicit_portsyy~~rcZ|jj}|s|jrd}|S)zNEncoded path of URL. / for absolute URLs without path part. ru)r:rHrwrs rraw_pathz URL.raw_path s)iinnt'')C rc8|j|jS)zNDecoded path of URL. / for absolute URLs without path part. )_PATH_UNQUOTERrr}s rrHzURL.paths""4==11rcXtt|jd}t|S)zA MultiDictProxy representing parsed query parameters in decoded representation. Empty value if URL has no query part. Tkeep_blank_values)r rraw_query_stringr rs rraz URL.query!s& $"7"74PQc""rc.|jjS)zOEncoded query part of URL. Empty string if query is missing. )r:rar}s rrzURL.raw_query_string,syyrc8|j|jS)zODecoded query part of URL. Empty string if query is missing. ) _QS_UNQUOTERrr}s rrfzURL.query_string5s  !6!677rch|js |jS|jd|jS)zDecoded path of URL with query.?)rfrHr}s rpath_qsz URL.path_qs>s3  99 ))Ad//011rch|js |jS|jd|jS)zEncoded path of URL with query.r)rrr}s r raw_path_qszURL.raw_path_qsEs3$$== --$"7"7!899rc.|jjS)zUEncoded fragment part of URL. Empty string if fragment is missing. )r:rbr}s r raw_fragmentzURL.raw_fragmentLrrc8|j|jS)zUDecoded fragment part of URL. Empty string if fragment is missing. )rrr}s rrbz URL.fragmentUrrcT|jj}|jr3|sdg}t |Sdg|ddjdz}t |S|j dr#dg|ddjdz}t |S|jd}t |S)zjA tuple containing encoded *path* parts. ('/',) for absolute URLs if *path* is missing. rurN)r:rHrwrrtuple)r'rHrs r raw_partsz URL.raw_parts^syy~~    U| QRs 33 U| s#QRs 33U| 3U|rc@tfdjDS)zjA tuple containing decoded *path* parts. ('/',) for absolute URLs if *path* is missing. c3@K|]}j|ywr*r).0partr's r zURL.parts..ysEdT^^D)E)rrr}s`rrz URL.partsrsEdnnEEErcH|j}|r|dk(rB|js |jr(t|jj dddS|S|j d}|jj dj|dddd}t|dS) z]A new URL with last part of path removed and cleaned up query and fragment. rur!)rarbTriNr)rrrr9r:rxrr)r'rHrr0s rparentz URL.parent{s }}ts{  D$9$9499--B-DdSSK 3ii  chhuSbz&:"r R3%%rc^|j}|jr |dd}|sy|dS|dS)zThe last part of raw_parts.rNr!r)rrw)r'rs rraw_namez URL.raw_names>    !"IERy 9 rc8|j|jS)zThe last part of parts.)rrr}s rr&zURL.names~~dmm,,rc||j}|jd}d|cxkrt|dz krny||dSy)N.rrr!)rrfindlen)r'r&is r raw_suffixzURL.raw_suffixsB}} JJsO q 3t9q= 8Orc8|j|jSr*)rrr}s rsuffixz URL.suffixs~~doo..rc|j}|jdry|jd}td|j dddDS)Nrr7c3&K|] }d|z yw)rNr7)rrs rrz#URL.raw_suffixes..sDfS6\Dsr)rendswithlstriprr)r'r&s r raw_suffixeszURL.raw_suffixessH}} == {{3D 30CDDDrc@tfdjDS)Nc3@K|]}j|ywr*r)rrr's rrzURL.suffixes..sLT^^F+Lr)rrr}s`rsuffixesz URL.suffixessL$:K:KLLLrcxt|dkDr,t|dkDr|jds tdyyy)znEnsure that path in URL with authority starts with a leading slash. Raise ValueError if not. rruzCPath in a URL with authority should start with a slash ('/') if setN)rrrOrFs rrYz$URL._validate_authority_uri_abs_paths> t9q=SY]4??33GU 4H]=rc|jd}g}|D]0}|dk(r |j|dk(r |j|2|ddvr|jddj |S#t$rYgwxYw)Nru..rrrrr!)rpop IndexErrorrr)r^rHsegments resolved_pathsegs rrXzURL._normalize_paths::c?  *Cd{!%%' $$S) * B<; &   $xx &&!" sA22 A>=A>c$ |jd\}}}t|}|j}|r|d|zz }|jdk(rd|zdz}|S#t$r5|j }|s|j r|cYSt|}Y|SwxYw)Nr[]) partitionr compressedversionrOlowerisascii _idna_encode)r^rGhumanipsepzones r _encode_hostzURL._encode_hosts ( NN3/MBTBB==Dd "zzQTzC'  &::tDzlKL L!PQ Qii II  ((s||S\\SWX     rric|s2|j|}|jr|j|}t|dkDr |ddk7rd|z}t |j j |dddS)z$Return a new URL with path replaced.rrur!rTri)rjrwrXrr9r:rx)r'rHrAs r with_pathz URL.with_pathtss$$T*D!++D1 t9q=T!W^:D499%%4rB%GQUVVrc#K|D]m\}}t|ttfr-|D]'}||dz||j|z)I||dz||j|zoyw)N=)rPlistr _query_var)r^r#pairskeyr0rs r_query_seq_pairszURL._query_seq_pairs~s FHC#e}-HA ++fS^^A5F.GGGHSkC'&1D*EEE  FsA4A6ct|}t|tr|St|trTt j |r t dt j|r t dtt|St|tr|turtt|Stdj||)Nzfloat('inf') is not supportedzfloat('nan') is not supportedzMInvalid variable type: value should be str, int or float, got {!r} of type {}) rM issubclassrNfloatmathisinfrOisnanr.rrQformat)rr^s rr5zURL._query_vars1g c3 H c5 !zz!} !@AAzz!} !@AAuQx= c3 CtOs1v;  3  rc@|rt|dkDr td|}nt|dk(r|d}n td|d}|St|tr=jdj j |j}|St|trj|}|St|tttfr tdt|tr)jdj fd|D}|Std) Nrz7Either kwargs or single query parameter must be presentrr!&zAInvalid query type: bytes, bytearray and memoryview are forbiddenc3jK|]*\}}|dzj|z,yw)r3N)r5)rkrr#r's rrz%URL._get_str_query..s5AEAq C&);"<<s03zRInvalid query type: only str, mapping or sequence of (key, value) pairs is allowed)rrOrPr_QUERY_PART_QUOTERrr8itemsrNrkbytes bytearray memoryviewrQr)r'argskwargsrar#s` @r_get_str_queryzURL._get_str_querys- 4y1} ME Y!^GEVW W =E2 1w ',,FHHT2265;;=IJE, +s #&&u-E( 'y*= >S x (,,F HHINE < rc|j|i|}t|jj|jj|dS)a[Return a new URL with query part replaced. Accepts any Mapping (e.g. dict, multidict.MultiDict instances) or str, autoencode the argument if needed. A sequence of (key, value) pairs is supported as well. It also can take an arbitrary number of keyword arguments. Clear query if None is passed. )rHraTri)rKr9r:rxrH)r'rIrJ new_querys rrmzURL.with_querysI(D''88  II  DIINN)  Dd  rc |j|i|}tt|d}t|j}|j |t |j j|j|dS)z)Return a new URL with query part updated.Tr)rari)rKr rraupdater9r:rx)r'rIrJsrMras rrzURL.update_queryso D   0 0iTBC $**% Y499%%D,?,?,F%GQUVVrc|d}n,t|ts td|j|}|j|k(r|St |j j|dS)zReturn a new URL with fragment replaced. Autoencode fragment if needed. Clear fragment to default if None is passed. r!zInvalid fragment type)rbTri)rPrNrQrlrr9r:rx)r'rbrs r with_fragmentzURL.with_fragmentsg  LHc*34 400:L    ,K499%%|%>rc t|jd}t|jd}|j}|r|j |jd}t|j d}dj d|jjD}t|jd}tt|j|j||||jjd |||S) z.@s5 1 NN<73\!W5M N s35r!Fr)r[rerVrGrrHrrarErbr rrcrTr:rS)r'rerVrGrHrfrbs r human_reprzURL.human_repr8sDIIy1 y9yy $$TYYd$;DDIIt,xx  ((*    r2  !!IINN % "   r)r!)F)FTF)]r%rr5 __slots__rr"r!rjrWrkrZrDrlr[rrrrr] classmethodrprrrzr~rrrrrrrrrrrrrrwrrrpropertyrcrrrdrrerrVrrGrSrrrHrarrfrrrrbrrrrr&rrrr staticmethodrYrXrrTr%r(r*r,r/r1r8r5rKrmrrRrTrWrr\r7rrr9r96s_N#Ie$G IeDL$$7N6dERM6VEO fuEFE: f- Ic*N%L.d.`    CCJM ;) ' & ' &  *( $ ) $& &        --""11""!! EE  22##8822 :: ""11&FF & &  --//EEMM''8*QV2L 4 2 0 &*/WFF  $&P (WL& @$*?" rr9c|s|Sd|zD]&}||vs|j|dt|d}(|jr|Sdjd|DS)Nr02Xr!c3VK|]!}|jr|n t|#ywr*) isprintabler)rcs rrz_human_quote..^s!A! 1U1X5As'))replaceordrdr)rPr@res rr[r[Vsf  6\/ 6 !qQ -.A/ }} 77AqA AArc tj|jdS#t$r#|jdjdcYSwxYw)Nridna)rjdecoderD UnicodeError)rs rrrdsH2{{3::g.// 2zz'"))&112s#&)AAc tj|djdS#t$r#|jdjdcYSwxYw)NT)uts46rrj)rjrDrkrl)rGs rrrlsL3{{4t,33G<< 3{{6"))'223s%()AAcTtjtjyr*)r cache_clearrr7rrrprptsrcTtjtjdS)N) idna_encode idna_decode)r cache_inforr7rrrtrtzs&$..0#..0 ridna_encode_sizeidna_decode_sizectj|tjatj|tjayr*) functools lru_cacher __wrapped__rrus rcache_configurer|s@99&&'789Q9QRL89&&'789Q9QRLr)$ryr<rKcollections.abcrr ipaddressr urllib.parserrrr r r rj multidictr r _quotingrrrr\r6rrr9r[ _MAXCACHErzrrrprtr|r7rrrs - UU /(cC@ 86 ==>\ \ \ ~ B  Y2 2Y3 3 (1ISSr