a 97aЋ@sNdZddlmZmZmZddlmZmZmZm Z m Z m Z ddl m Z ddlZddlZddlZgdZgdZgdZgd Zgd Zgd Zgd Zd ZdZiZddZdZdZddZeefddZeefddZ ddZ!Gddde"Z#Gddde"Z$Gdd d e"Z%Gd!d"d"e%e#Z&Gd#d$d$e%e$Z'dd%lm(Z(e(d&d'Z)e(d(d)Z*e(d*d+Z+e&Z,Gd,d&d&e)e#Z-Gd-d(d(e*e&Z.Gd.d*d*e+e&Z/Gd/d0d0e)e$Z0Gd1d2d2e*e'Z1Gd3d4d4e+e'Z2d5d6Z3e3[3dd9d:Z4d;d<Z5dd=d>Z6dd?d@Z7dAdBZ8dCdDZ9ddEdFZ:dGdHZ;dIZe?dNZ@ddQdRZAddTdUZBddVdWZCddXdYZDeEedZZFeeFZGiZHGd[d\d\ejIZJdd^d_ZKdd`daZLddbdcZMddddeZNdfdgZOdhdiZPdaQdjdkZRdaSdldmZTdaUdndoZVdaWdpdqZXdaYdrdsZZda[ddudvZ\da]dwdxZ^da_dydzZ`d{d|Zadabd}d~ZcdS)a Ported using Python-Future from the Python 3.3 standard library. Parse (absolute and relative) URLs. urlparse module is based upon the following RFC specifications. RFC 3986 (STD66): "Uniform Resource Identifiers" by T. Berners-Lee, R. Fielding and L. Masinter, January 2005. RFC 2732 : "Format for Literal IPv6 Addresses in URL's by R.Hinden, B.Carpenter and L.Masinter, December 1999. RFC 2396: "Uniform Resource Identifiers (URI)": Generic Syntax by T. Berners-Lee, R. Fielding, and L. Masinter, August 1998. RFC 2368: "The mailto URL scheme", by P.Hoffman , L Masinter, J. Zawinski, July 1998. RFC 1808: "Relative Uniform Resource Locators", by R. Fielding, UC Irvine, June 1995. RFC 1738: "Uniform Resource Locators (URL)" by T. Berners-Lee, L. Masinter, M. McCahill, December 1994 RFC 3986 is considered the current standard and any future changes to urlparse module should conform with it. The urlparse module is currently not entirely compliant with this RFC due to defacto scenarios for parsing, and for backward compatibility purposes, some parsing quirks from older RFCs are retained. The testcases in test_urlparse.py provides a good indicator of parsing behavior. )absolute_importdivisionunicode_literals)byteschrdictintrangestr)raise_with_tracebackN)urlparse urlunparseurljoin urldefragurlsplit urlunsplit urlencodeparse_qs parse_qslquote quote_plusquote_from_bytesunquote unquote_plusunquote_to_bytes)ftphttpgophernntpimapwaisfilehttpsshttpmmsprosperortsprtspusftpsvnsvn+ssh)rrrrtelnetrr r!r$r"r#snewsr%r&r'rsyncr(r*r+r)nfsgitzgit+ssh)rhdlr%rrr"r#r&r'sipsipsr$r(r)tel) rr1mailtonewsr,r rr-r2r3) rr rr"r#r$rr&r'r2r3r() rr1rrr6rr r"r#r-r!r%r(zAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.cCsttdS)z,Clear the parse cache and the quoters cache.N) _parse_cacheclear _safe_quotersr;r;x/private/var/folders/s6/9n5zrl012gv99k63s4q6ccsd4s6mqz/T/pip-target-f5cq3f2q/lib/python/future/backports/urllib/parse.py clear_cacheNsr=asciistrictcCs|SNr;)objr;r;r<_noop]srBcCs |||Sr@encode)rAencodingerrorsr;r;r<_encode_result`srGcstfdd|DS)Nc3s"|]}|r|ndVqdS)r(Ndecode.0xrErFr;r< fz_decode_args..)tuple)argsrErFr;rMr< _decode_argsdsrRcGsVt|dt}|ddD]}|rt|t|krtdq|rH|tfSt|tfS)Nrz$Cannot mix str and non-str arguments) isinstancer TypeErrorrBrRrG)rQ str_inputargr;r;r< _coerce_argshs  rXc@seZdZdZdZdddZdS) _ResultMixinStrz>Standard approach to encoding parsed results from str to bytesr;r>r?cs|jfdd|DS)Nc3s|]}|VqdSr@rCrJrMr;r<rN~rOz)_ResultMixinStr.encode..)_encoded_counterpartselfrErFr;rMr<rD}sz_ResultMixinStr.encodeN)r>r?)__name__ __module__ __qualname____doc__ __slots__rDr;r;r;r<rYysrYc@seZdZdZdZdddZdS) _ResultMixinBytesz>Standard approach to decoding parsed results from bytes to strr;r>r?cs|jfdd|DS)Nc3s|]}|VqdSr@rHrJrMr;r<rNrOz+_ResultMixinBytes.decode..)_decoded_counterpartr[r;rMr<rIsz_ResultMixinBytes.decodeN)r>r?)r]r^r_r`rarIr;r;r;r<rbsrbc@sDeZdZdZdZeddZeddZeddZed d Z d S) _NetlocResultMixinBasezHShared methods for the parsed result objects containing a netloc elementr;cCs |jdSNr _userinfor\r;r;r<usernamesz_NetlocResultMixinBase.usernamecCs |jdS)NrSrfrhr;r;r<passwordsz_NetlocResultMixinBase.passwordcCs(|jd}|sd}n|dur$|}|Sre) _hostinfolower)r\hostnamer;r;r<rms  z_NetlocResultMixinBase.hostnamecCs:|jd}|dur6t|d}d|kr0dks6ndS|S)NrS ri)rkr)r\portr;r;r<ros   z_NetlocResultMixinBase.portN) r]r^r_r`rapropertyrirjrmror;r;r;r<rds   rdc@s(eZdZdZeddZeddZdS)_NetlocResultMixinStrr;cCsD|j}|d\}}}|r4|d\}}}|s:///;?# Return a 6-tuple: (scheme, netloc, path, params, query, fragment). Note that we don't break the components up in smaller bits (e.g. netloc is a single string) and we don't expand % escapes.;r()rXr uses_params _splitparamsr) rschemeallow_fragments_coerce_result splitresultruqueryrparamsresultr;r;r<r $s r cCsRd|vr,|d|d}|dkr6|dfSn |d}|d|||ddfS)N/rrr(rS)findrfind)rir;r;r<r4s   rcCsHt|}dD]"}|||}|dkr t||}q |||||dfS)Nz/?#r)lenrmin)rstartdelimcwdelimr;r;r< _splitnetloc=s   rc CsXt||\}}}t|}|||t|t|f}t|d}|rF||StttkrXtd}}}|d} | dkr|d| dkrJ|d|  }|| dd}|dddkrt |d\}}d |vrd |vsd |vrd |vrt d |rd |vr| d d\}}d |vr*| d d\}}t |||||} | t|<|| S|d| D]} | tvrVqqV|| dd} | rtdd| Dr|d|  | }}|dddkrt |d\}}d |vrd |vsd |vrd |vrt d |rd |vr| d d\}}d |vr8| d d\}}t |||||} | t|<|| S)aParse a URL into 5 components: :///?# Return a 5-tuple: (scheme, netloc, path, query, fragment). Note that we don't break the components up in smaller bits (e.g. netloc is a single string) and we don't expand % escapes.Nr(rsrrrS//r}r~zInvalid IPv6 URLr?css|]}|dvVqdS) 0123456789Nr;rKrr;r;r<rNlrOzurlsplit..)rXbooltyper8getrMAX_CACHE_SIZEr=rrlr ValueErrorsplitr scheme_charsany) rrrrkeycachedrurrrvrrestr;r;r<rEsd         rcCs<t|\}}}}}}}|r&d||f}|t|||||fS)zPut a parsed URL back together again. This may result in a slightly different, but equivalent URL, if the URL that was parsed originally had redundant delimiters, e.g. a ? with an empty query (the draft states that these are equivalent).z%s;%s)rXr) componentsrrurrrrrr;r;r<r }s  r cCst|\}}}}}}|s4|r`|tvr`|dddkr`|rP|dddkrPd|}d|pXd|}|rp|d|}|r|d|}|r|d |}||S) akCombine the elements of a tuple as returned by urlsplit() into a complete URL as a string. The data argument can be any five-item iterable. This may result in a slightly different, but equivalent URL, if the URL that was parsed originally had unnecessary delimiters (for example, a ? with an empty query; the RFC states that these are equivalent).NrrrSrr(rsrr)rX uses_netloc)rrrurrrrr;r;r<rs    rcCs|s|S|s|St||\}}}t|d|\}}}}}} t|||\} } } } }}| |ks`| tvrh||S| tvr| r|t| | | | ||fS|} | dddkr|t| | | | ||fS| s| s|} |} |s|}|t| | | | ||fS|ddd| d}|ddkrd|d<d|vr2|dqd}t|d}||kr||dkr||ddvr||d|d=q2|d}qBqq2|ddgkrd|d<n*t|d kr|ddkrdg|d d<|t| | d|| ||fS) zaJoin a base URL and a possibly relative URL to form an absolute interpretation of the latter.r(NrSr...)r(rr) rXr uses_relativerr rremoverjoin)baserrrbschemebnetlocbpathbparamsbquery bfragmentrrupathrrrsegmentsrnr;r;r<rsf          rc CsTt|\}}d|vr>t|\}}}}}}t|||||df}nd}|}|t||S)zRemoves any existing fragment from URL. Returns a tuple of the defragmented URL and the fragment. If the URL contained no fragments, the second element is the empty string. rr()rXr r r) rrsrpaqfragdefragr;r;r<rs r0123456789ABCDEFabcdefccs8|]0}tD]&}||tt||dgfVq qdS)N)_hexdigrDrr)rKrbr;r;r<rNs rNc Cs|s|jtdSt|tr&|d}t|}|d}t|dkrH|S|dg}|j}|ddD]P}z(|t|dd||ddWqdty|d||Yqd0qdtd |S)z,unquote_to_bytes('abc%20def') -> b'abc def'.rOutf-8%rSrNr) rrrTr rDrappend _hextobyteKeyErrorr)stringbitsresritemr;r;r<rs&      rz([-]+)rreplacecCsd|vr|j|S|durd}|dur*d}t|}|dg}|j}tdt|dD],}|t|||||||dqTd|S) aReplace %xx escapes by their single-character equivalent. The optional encoding and errors parameters specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. By default, percent-encoded sequences are decoded with UTF-8, and invalid sequences are replaced by a placeholder character. unquote('abc%20def') -> 'abc def'. %NrrrrSrr()r_asciirerr rrrIr)rrErFrrrrr;r;r<rs   rFc CsJi}t|||||d}|D]*\}}||vr:|||q|g||<q|S)aOParse a query given as a string argument. Arguments: qs: percent-encoded query string to be parsed keep_blank_values: flag indicating whether blank values in percent-encoded queries should be treated as blank strings. A true value indicates that blanks should be retained as blank strings. The default false value indicates that blank values are to be ignored and treated as if they were not included. strict_parsing: flag indicating what to do with parsing errors. If false (the default), errors are silently ignored. If true, errors raise a ValueError exception. encoding and errors: specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. rM)rr) qskeep_blank_valuesstrict_parsingrErF parsed_resultpairsnamevaluer;r;r<rs  rc Cst|\}}dd|dD}g}|D]}|s6|s6q(|dd} t| dkrr|r`td|f|r(| dnq(t| ds|r(| d d d } t| ||d } || } | dd d } t| ||d } || } || | fq(|S) a;Parse a query given as a string argument. Arguments: qs: percent-encoded query string to be parsed keep_blank_values: flag indicating whether blank values in percent-encoded queries should be treated as blank strings. A true value indicates that blanks should be retained as blank strings. The default false value indicates that blank values are to be ignored and treated as if they were not included. strict_parsing: flag indicating what to do with parsing errors. If false (the default), errors are silently ignored. If true, errors raise a ValueError exception. encoding and errors: specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. Returns a list, as G-d intended. cSs g|]}|dD]}|qqS)rr)rKs1s2r;r;r< TrOzparse_qsl..&=rSrzbad query field: %rr(r+ rM)rXrrrrrr) rrrrErFrrr name_valuenvrrr;r;r<r<s,    rcCs|dd}t|||S)zLike unquote(), but also replace plus signs by spaces, as required for unquoting HTML form values. unquote_plus('%7e/abc+def') -> '~/abc def' rr)rr)rrErFr;r;r<rls rsAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-c@s(eZdZdZddZddZddZdS) QuoterzA mapping from bytes (in range(0,256)) to strings. String values are percent-encoded byte values, unless the key < 128, and in the "safe" set (either the specified safe set, or default set). cCstt||_dS)zsafe: bytes object.N) _ALWAYS_SAFEunionrsafe)r\rr;r;r<__init__szQuoter.__init__cCs dt|S)Nz )rrhr;r;r<__repr__szQuoter.__repr__cCs(||jvrt|nd|}|||<|S)Nz%{0:02X})rrformat)r\rrr;r;r< __missing__szQuoter.__missing__N)r]r^r_r`rrrr;r;r;r<r|srrcCsbt|tr8|s|S|durd}|dur*d}|||}n |durHtd|durXtdt||S)aquote('abc def') -> 'abc%20def' Each part of a URL, e.g. the path info, the query, etc., has a different set of reserved characters that must be quoted. RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists the following reserved characters. reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | "," Each of these characters is reserved in some component of a URL, but not necessarily in all of them. By default, the quote function is intended for quoting the path section of a URL. Thus, it will not encode '/'. This character is reserved, but in typical usage the quote function is being called on a path where the existing slash characters are used as reserved characters. string and safe may be either str or bytes objects. encoding must not be specified if string is a str. The optional encoding and errors parameters specify how to deal with non-ASCII characters, as accepted by the str.encode method. By default, encoding='utf-8' (characters are encoded with UTF-8), and errors='strict' (unsupported characters raise a UnicodeEncodeError). Nrr?z,quote() doesn't support 'encoding' for bytesz*quote() doesn't support 'errors' for bytes)rTr rDrUr)rrrErFr;r;r<rs rcCslt|trd|vs$t|tr2d|vr2t||||St|trFtd}ntd}t|||||}|ddS)zLike quote(), but also replace ' ' with '+', as required for quoting HTML form values. Plus signs in the original string are escaped unless they are included in safe. It also does not have safe default to '/'. r r)rTr rrr)rrrErFspacer;r;r<rs  rcst|ttfstd|s"tdSt|}t|trFt|dd}nt|}tdd|D}|t|sv|Sz t |Wn$t yt |j t |<Yn0td fdd|DS)zLike quote(), but accepts a bytes object rather than a str, and does not perform string-to-bytes encoding. It always returns an ASCII string. quote_from_bytes(b'abc def?') -> 'abc%20def%3f' z!quote_from_bytes() expected bytesr(r>ignorecSsg|]}|dkr|qS)r;rr;r;r<rrOz$quote_from_bytes..csg|] }|qSr;r;)rKcharquoterr;r<rrO)rTr bytearrayrUr rDrstrip_ALWAYS_SAFE_BYTESrIr:rr __getitem__r)bsrr;rr<rs    rc Cs t|dr|}nNzt|r0t|dts0tWn.ty`t\}}}ttd|Yn0g}|s|D]j\} } t| t rt | |} nt t | |||} t| t rt | |} nt t | |||} | | d| qnn |D]\} } t| t rt | |} nt t | |||} t| t r@t | |} | | d| qt| t rnt | |||} | | d| qz t| } Wn8tyt t | |||} | | d| Yq0| D]B} t| t rt | |} nt t | |||} | | d| qqt d |S)a#Encode a sequence of two-element tuples or dictionary into a URL query string. If any values in the query arg are sequences and doseq is true, each sequence element is converted to a separate parameter. If the query arg is a sequence of two-element tuples, the order of the parameters in the output will match the order of parameters in the input. The query arg may be either a string or a bytes type. When query arg is a string, the safe, encoding and error parameters are sent the quote_plus for encoding. itemsrz1not a valid non-string sequence or mapping objectrr)hasattrrrrTrPrUsysexc_infor rrr rr) rdoseqrrErFtyvatblkrrLeltr;r;r<rsR                 rcCsHt|trDz|d}Wn&tyBtdt|dYn0|S)zto_bytes(u"URL") --> 'URL'.ASCIIzURL z contains non-ASCII characters)rTr rDrI UnicodeErrorreprrr;r;r<to_bytesHs    rcCs`t|}|dddkr<|dddkr<|dd}|dddkr\|dd}|S)z8unwrap('') --> 'type://host/path'.NrSzURL:)r striprr;r;r<unwrapUs    r#cCsVtdurddl}|dat|}|rN|d}||t|ddfSd|fS)z:splittype('type:opaquestring') --> 'type', 'opaquestring'.Nrz ^([^/:]+):rS) _typeprogrecompilematchgrouprlr)rr%r'rr;r;r< splittype^s   r)cCsbtdurddl}|dat|}|rZ|d}|d}|rR|dsRd|}||fSd|fS)z;splithost('//host[:port]/path') --> 'host[:port]', '/path'.Nrz^//([^/?]*)(.*)$rSrr) _hostprogr%r&r'r( startswith)rr%r' host_portrr;r;r< splithostls    r-cCs<tdurddl}|dat|}|r4|ddSd|fS)zJsplituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.Nrz ^(.*)@(.*)$rSr) _userprogr%r&r'r(hostr%r'r;r;r< splituser}s   r1cCs@tdurddl}|d|jat|}|r8|ddS|dfS)z/splitpasswd('user:passwd') -> 'user', 'passwd'.Nrz^([^:]*):(.*)$rSr) _passwdprogr%r&Sr'r()userr%r'r;r;r< splitpasswds  r5cCs<tdurddl}|dat|}|r4|ddS|dfS)z*splitport('host:port') --> 'host', 'port'.Nrz^(.*):([0-9]+)$rSr) _portprogr%r&r'r(r/r;r;r< splitports   r7rcCsxtdurddl}|dat|}|rp|dd\}}z|sFtdt|}Wntyfd}Yn0||fS||fS)zSplit host and port, returning numeric port. Return given default port if no ':' found; defaults to -1. Return numerical port if a valid number are found after ':'. Return None if ':' but not a valid number.Nrz ^(.*):(.*)$rSrz no digits) _nportprogr%r&r'r(rr)r0defportr%r'ronportr;r;r< splitnports      r;cCs<tdurddl}|dat|}|r4|ddS|dfS)z/splitquery('/path?query') --> '/path', 'query'.Nrz^(.*)\?([^?]*)$rSr) _queryprogr%r&r'r(rr%r'r;r;r< splitquerys   r>cCs<tdurddl}|dat|}|r4|ddS|dfS)z)splittag('/path#tag') --> '/path', 'tag'.Nrz^(.*)#([^#]*)$rSr)_tagprogr%r&r'r(r=r;r;r<splittags   r@cCs|d}|d|ddfS)zksplitattr('/path;attr1=value1;attr2=value2;...') -> '/path', ['attr1=value1', 'attr2=value2', ...].rrrSNr)rwordsr;r;r< splitattrs rBcCs<tdurddl}|dat|}|r4|ddS|dfS)z-splitvalue('attr=value') --> 'attr', 'value'.Nrz^([^=]*)=(.*)$rSr) _valueprogr%r&r'r()attrr%r'r;r;r< splitvalues   rE)r(T)r)r(T)T)rr)FFrr)FFrr)rr)rNN)r(NN)r)Fr(NN)r)dr` __future__rrrZfuture.builtinsrrrrr r Z future.utilsr r%r collections__all__rrrnon_hierarchical uses_query uses_fragmentrrr8r=_implicit_encoding_implicit_errorsrBrGrRrXobjectrYrbrdrqrr_DefragResultBase_SplitResultBase_ParseResultBase ResultBaserrrrrrrr rrrr rrrrrrr&rrrrr frozensetrr r: defaultdictrrrrrrr#r$r)r*r-r.r1r2r5r6r7r8r;r<r>r?r@rBrCrEr;r;r;r<s              8  5    0  ,   ]