B `@s(ddlZddlZddlZddlmZmZddlmZddlm Z m Z m Z m Z m Z mZddlmZmZddlZddlZddlmZmZdd dd d ZeZeed d d ZGdddZeGdddZddZdZeedda eedda!eddZ"eddZ#eeedddZ$dS) N)MappingSequence) ip_address) SplitResult parse_qslurljoinurlsplit urlunsplitquote) MultiDictMultiDictProxy)_Quoter _UnquoterPi)httphttpswswss)objreturncCs d|_|S)NZyarl) __module__)rrd/private/var/folders/7j/8686xlfs15q3tgljmghtvg0r0000gn/T/pip-target-isidps9b/lib/python/yarl/_url.pyrewrite_modulesrc@s,eZdZdZddZefddZddZdS) 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. cCs:||_y |j|_Wntk r,d|_YnX|j|_dS)N)wrapped__doc__AttributeError__name__name)selfrrrr__init__$s   zcached_property.__init__cCsB|dkr |S|j|j|}||k r(|S||}||j|j<|S)N)_cachegetr!r)r"instowner _sentinelvalrrr__get__,s  zcached_property.__get__cCs tddS)Nzcached property is read-only)r)r"r&valuerrr__set__6szcached_property.__set__N)r r __qualname__rr#sentinelr*r,rrrrrs rc @sfeZdZdZeddZeZeddddZedddZedd d dd Z edd d d Z edd dd Z edddZ eddZ eZeddZed dZddddddZedddddddddddd ddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Ze d1d2d3Z!d4d5Z"d6d7Z#d8d9Z$d:d;Z%dd?Z'e(d@dAZ)e(dBdCZ*e+dDdEZ,e(dFdGZ-e+dHdIZ.e(dJdKZ/e+dLdMZ0e(dNdOZ1e+dPdQZ2e(dRdSZ3e(dTdUZ4e(dVdWZ5e+dXdYZ6e+dZd[Z7e(d\d]Z8e+d^d_Z9e+d`daZ:e+dbdcZ;e(dddeZe+djdkZ?e+dldmZ@e+dndoZAe+dpdqZBeCdrdsZDedtduZEeFjGdvkreddwdxZHneddydxZHeddzd{ZId|d}ZJd~dZKddZLddZMddZNddddZOeddZPeCddZQddZRddZSddZTddZUddZVddZWddZXdS)URL)r$_valF)requotez@:z/+)safe protectedr1)r2r3z?/:@z=+&;T)r2r3qsr1)r2r3r4)r2r4r1)r2r1)r2+)unsafe)r4rN)encodedstrictc Csh|dk rtdt||kr"|St|tkr8t|}n:t|tkrR|srtdn t|trjtt|}ntd|sN|dsd}d}nh|j }|dkrtdy |j }Wn,tk r}ztd|Wdd}~XYnX|j |j |j ||ddd }||d }|r||}|j||d ||d } ||d } t|d||| | }t|} || _i| _| S)Nzstrict parameter is ignoredz$Cannot apply decoding to SplitResultz#Constructor parameter should be strr rz/Invalid URL: host is required for absolute urlsz/Invalid URL: port can't be converted to integerT)encoder1)hostpathr)warningswarntypestrrr ValueError isinstance TypeErrorhostnameport _make_netlocusernamepassword_PATH_REQUOTER_normalize_path _validate_authority_uri_abs_path_QUERY_REQUOTER_FRAGMENT_REQUOTERobject__new__r0r$) clsr)r7r8netlocr;rGer<queryfragmentr"rrrrQsL          z URL.__new__) scheme authorityuserrJr;rGr<rU query_stringrVr7c CsH|r|s|s|s|rtd|r,|s,td|r<| rs         zURL.__truediv__cCs ||S)N) update_query)r"rUrrr__mod__Ssz URL.__mod__)rcCs$t|jjp |jjp |jjp |jjS)N)boolr0rSr<rUrV)r"rrr__bool__Vsz URL.__bool__cCs|jfS)N)r0)r"rrr __getstate__[szURL.__getstate__cCs>|ddkr*t|dtr*|dd|_n |^|_}i|_dS)Nrr r0)rDdictr0r$)r"stateZunusedrrr __setstate__^s zURL.__setstate__cCs |jdk S)zA check for absolute URLs. Return True for absolute ones (having scheme or starting with //), False otherwise. N)raw_host)r"rrrrffszURL.is_absolutecCs0|jdkrdSt|j}|dkr&dS|j|kS)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. NF)rG DEFAULT_PORTSr%rW)r"defaultrrris_default_portos   zURL.is_default_portcCsX|std|jjs td|j}|dd|j|j}|j|dddd}t|ddS)z}Return an URL with scheme, host and port parts only. user, password, path, query and fragment are removed. zURL should be absolutezURL should have schemeNr)rSr<rUrVT)r7) rfrCr0rWrHrFrGrgr/)r"vrSr)rrrorigin~sz URL.origincCs,|std|jjddd}t|ddS)zhReturn a relative part of the URL. scheme, user, password, host and port are removed. zURL should be absoluter)rWrST)r7)rfrCr0rgr/)r"r)rrrrelativesz URL.relativecCs|jjS)zdScheme for absolute URLs. Empty string for relative URLs or URLs starting with // )r0rW)r"rrrrWsz URL.schemecCs|jjS)zQEncoded authority part of URL. Empty string for relative URLs. )r0rS)r"rrr raw_authorityszURL.raw_authoritycCs|j|j|j|j|jddS)zQDecoded authority part of URL. Empty string for relative URLs. F)r[)rHrYrJr;rG)r"rrrrXsz URL.authoritycCs|jj}|sdS|S)zEEncoded user part of URL. None if user is missing. N)r0rI)r"rorrrraw_usersz URL.raw_usercCs ||jS)zEDecoded user part of URL. None if user is missing. ) _UNQUOTERr)r"rrrrYszURL.usercCs|jjS)zMEncoded password part of URL. None if password is missing. )r0rJ)r"rrr raw_passwordszURL.raw_passwordcCs ||jS)zMDecoded password part of URL. None if password is missing. )rr)r"rrrrJsz URL.passwordcCs|jjS)zDEncoded host part of URL. None for relative URLs. )r0rF)r"rrrrs z URL.raw_hostcCs&|j}|dkrdSd|kr|St|S)zDDecoded host part of URL. None for relative URLs. N%)r _idna_decode)r"rawrrrr;s zURL.hostcCs|jjpt|jjS)zPort part of URL, with scheme-based fallback. None for relative URLs or URLs without explicit port and scheme without default port substitution. )r0rGrr%rW)r"rrrrGszURL.portcCs|jjS)zyPort part of URL, without scheme-based fallback. None for relative URLs or URLs without explicit port. )r0rG)r"rrr explicit_portszURL.explicit_portcCs|jj}|s|rd}|S)zNEncoded path of URL. / for absolute URLs without path part. re)r0r<rf)r"rorrrraw_path s z URL.raw_pathcCs ||jS)zNDecoded path of URL. / for absolute URLs without path part. )_PATH_UNQUOTERr)r"rrrr<szURL.pathcCstt|jdd}t|S)zA MultiDictProxy representing parsed query parameters in decoded representation. Empty value if URL has no query part. T)keep_blank_values)r rraw_query_stringr )r"rorrrrU"sz URL.querycCs|jjS)zOEncoded query part of URL. Empty string if query is missing. )r0rU)r"rrrr-szURL.raw_query_stringcCs ||jS)zODecoded query part of URL. Empty string if query is missing. ) _QS_UNQUOTERr)r"rrrrZ6szURL.query_stringcCs|js |jSd|j|jS)zDecoded path of URL with query.z{}?{})rZr<rc)r"rrrpath_qs?sz URL.path_qscCs|js |jSd|j|jS)zEncoded path of URL with query.z{}?{})rrrc)r"rrr raw_path_qsFszURL.raw_path_qscCs|jjS)zUEncoded fragment part of URL. Empty string if fragment is missing. )r0rV)r"rrr raw_fragmentMszURL.raw_fragmentcCs ||jS)zUDecoded fragment part of URL. Empty string if fragment is missing. )rr)r"rrrrVVsz URL.fragmentcCsl|jj}|r6|sdg}qddg|ddd}n.|drZdg|ddd}n |d}t|S)zjA tuple containing encoded *path* parts. ('/',) for absolute URLs if *path* is missing. rer N)r0r<rfrwrutuple)r"r<r{rrr raw_parts_s  z URL.raw_partscstfddjDS)zjA tuple containing decoded *path* parts. ('/',) for absolute URLs if *path* is missing. c3s|]}|VqdS)N)r).0part)r"rr zszURL.parts..)rr)r"r)r"rr{ssz URL.partscCsp|j}|r|dkr:|js|jr6t|jjdddddS|S|d}|jjd|ddddd}t|ddS) z]A new URL with last part of path removed and cleaned up query and fragment. rer)rUrVT)r7N)r<rUrV)rrrr/r0rgrwry)r"r<r{r)rrrparent|s    z URL.parentcCs8|j}|r,|dd}|s"dS|dSn|dSdS)zThe last part of raw_parts.r Nrr)rrf)r"r{rrrraw_names  z URL.raw_namecCs ||jS)zThe last part of parts.)rr)r"rrrr!szURL.namecCs.t|dkr*t|dkr*|ds*tddS)znEnsure that path in URL with authority starts with a leading slash. Raise ValueError if not. rrezCPath in a URL with authority should start with a slash ('/') if setN)lenrurC)r;r<rrrrMs"z$URL._validate_authority_uri_abs_pathc Cs~|d}g}xN|D]F}|dkrDy |WqZtk r@YqZXq|dkrPqq||qW|ddkrt|dd|S)Nrez...r)rz..r)rwpop IndexErrorrxry)rRr<segments resolved_pathsegrrrrLs     zURL._normalize_path)r=cCsy|d\}}}t|}Wn4tk rP|}|s@|rD|St|}Yn.X|j}|rh|d|7}|jdkr~d|d}|S)Nr[]) partitionrrClowerisascii _idna_encode compressedversion)rRr;humanipsepzonerrr _encode_hosts     zURL._encode_hostcCsy|d\}}}t|}WnHtk rd|}|r<|Sx|D]}|dkrBPqBW|St|}Yn.X|j}|r||d|7}|jdkrd|d}|S)Nrrrr)rrrCrrrr)rRr;rrrrcharrrrrs$     c Cs|r |jn|j}|r ||} n|} |r8| dt|} |dk rp|sJd}n |rV||}|rb||}|d|}n|r|r||}|r|d| } | S)N:r@) _REQUOTER_QUOTERrrB) rRrYrJr;rGr9r[r1quoterrorrrrHs&  zURL._make_netloccCs<t|tstd|s"tdt|jj|dddS)z&Return a new URL with scheme replaced.zInvalid scheme typez3scheme replacement is not allowed for relative URLs)rWT)r7) rDrBrErfrCr/r0rgr)r"rWrrr with_schemes  zURL.with_schemecCsn|j}|dkrd}n$t|tr0||}|j}ntd|sHtdt|jj | |||j |j dddS)zReturn a new URL with user replaced. Autoencode user if needed. Clear user/password if user is None. NzInvalid user typez1user replacement is not allowed for relative URLs)rST)r7) r0rDrBrrJrErfrCr/rgrHrFrG)r"rYr)rJrrr with_users   z URL.with_usercCsf|dkr nt|tr ||}ntd|s8td|j}t|jj| |j ||j |j dddS)zReturn a new URL with password replaced. Autoencode password if needed. Clear password if argument is None. NzInvalid password typez5password replacement is not allowed for relative URLs)rST)r7) rDrBrrErfrCr0r/rgrHrIrFrG)r"rJr)rrr with_password4s   zURL.with_passwordcCs\t|tstd|s"td|s.td|j}t|jj||j |j ||j dddS)zReturn a new URL with host replaced. Autoencode host if needed. Changing host for relative URLs is not allowed, use .join() instead. zInvalid host typez1host replacement is not allowed for relative URLszhost removing is not allowed)rST)r7) rDrBrErfrCr0r/rgrHrIrJrG)r"r;r)rrr with_hostMs z URL.with_hostc Csf|dk r$t|ts$tdt||s4td|j}t|jj |j |j |j |j |dddddS)z`Return a new URL with port replaced. Clear port to default if None is passed. Nz"port should be int or None, got {}z1port replacement is not allowed for relative URLsT)r9)rS)r7)rDintrErcrArfrCr0r/rgrHrIrJrF)r"rGr)rrr with_portesz URL.with_port)r7cCsZ|s ||}|r ||}t|dkr@|ddkr@d|}t|jj|dddddS)z$Return a new URL with path replaced.rrer)r<rUrVT)r7)r\rfrLrr/r0rg)r"r<r7rrr with_pathzs  z URL.with_pathccslxf|D]^\}}t|ttfrHxF|D] }||d|||Vq"Wq||d|||VqWdS)N=)rDlistr _query_var)rRrpairskeyr)rrrr_query_seq_pairss  "zURL._query_seq_pairscCst|}t|tr|St|trPt|r2tdt|rDtdtt|St|trn|t k rntt|St d ||dS)Nzfloat('inf') is not supportedzfloat('nan') is not supportedzMInvalid variable type: value should be str, int or float, got {!r} of type {}) rA issubclassrBfloatmathisinfrCisnanrrrErc)rrRrrrrs      zURL._query_varcs|rt|dkrtd|}nt|dkr4|d}ntd|dkrJd}nt|trrjd|}ndt|tr |}nNt|t t t frt dn4t|trΈjdfdd|D}nt d |S) Nrz7Either kwargs or single query parameter must be presentr r&zAInvalid query type: bytes, bytearray and memoryview are forbiddenc3s,|]$\}}|d|VqdS)rN)r)rkr)rr"rrrsz%URL._get_str_query..zRInvalid query type: only str, mapping or sequence of (key, value) pairs is allowed)rrCrDr_QUERY_PART_QUOTERryritemsrBr]bytes bytearray memoryviewrEr)r"argskwargsrUr)rr"r_get_str_querys2       zURL._get_str_querycOs(|j||}t|jj|jj|dddS)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. )r<rUT)r7)rr/r0rgr<)r"rr new_queryrrrr_s zURL.with_querycOsL|j||}tt|dd}t|j}||t|jj||dddS)z)Return a new URL with query part updated.T)r)rU)r7)rr rrUupdater/r0rg)r"rrsrrUrrrr}s    zURL.update_querycCsP|dkrd}nt|ts"tdn ||}|j|kr:|St|jj|dddS)zReturn a new URL with fragment replaced. Autoencode fragment if needed. Clear fragment to default if None is passed. NrzInvalid fragment type)rVT)r7)rDrBrEr^rr/r0rg)r"rVrrrr with_fragments     zURL.with_fragmentcCst|tstdd|kr"td||}|dkr.rF)r[)rrYrJr;rr<ryrUrrVr rrWrHr0rG)r"rYrJr;r<rZrVrrr human_repr)s,    zURL.human_repr)r)F)F)FTF)Yr rr- __slots__rrrr\rKr]rNrr^rOrrrrrQ classmethodrbrdrhrjrmrprqrrrsrtr|r~rrrrrfrrrpropertyrWrrrXrrYrrJrr;rGrrr<rUrrZrrrrVrr{rrr! staticmethodrMrLsys version_inforrHrrrrrrrrrr_r}rrryrrrrrr/:sG      08              (  r/cCsX|s|Sx.d|D]"}||kr||dt|}qW|rD|Sddd|DS)Nrz%{:02X}rcss"|]}|r|nt|VqdS)N) isprintabler )rcrrrrOsz_human_quote..)replacercordrry)rr6rrrrrGsrcCs6yt|dStk r0|ddSXdS)Nasciiidna)rdecoder9 UnicodeError)rrrrrUsrcCs:ytj|dddStk r4|ddSXdS)NT)uts46rr)rr9rr)r;rrrr]srcCsttdS)N)r cache_clearrrrrrresrcCsttdS)N)Z idna_encodeZ idna_decode)r cache_inforrrrrrksr)idna_encode_sizeidna_decode_sizecCs$t|tjat|tjadS)N) functools lru_cacher __wrapped__r)rrrrrcache_configuressr)%rrr?collections.abcrr ipaddressr urllib.parserrrrr r Z multidictr r rrZ_quotingrrrrPr.rrr/r _MAXCACHErrrrrrrrrrs<