o ,]Ћ@sVdZddlmZmZmZddlmZmZmZm 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@ddQdRZA S PddTdUZB S PddVdWZCddXdYZDeEedZZFeeFZGiZHGd[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;?/usr/lib/python3/dist-packages/future/backports/urllib/parse.py clear_cacheNs r=asciistrictcCs|SNr;)objr;r;r<_noop]srBcCs |||Sr@encode)rAencodingerrorsr;r;r<_encode_result` rGcstfdd|DS)Nc3s$|] }|r |ndVqdS)r(Ndecode.0xrErFr;r< fs"z_decode_args..)tuple)argsrErFr;rNr< _decode_argsdsrRcGsVt|dt}|ddD]}|rt|t|krtdq |r$|tfSt|tfS)Nrz$Cannot mix str and non-str arguments) isinstancer TypeErrorrBrRrG)rQ str_inputargr;r;r< _coerce_argshs rXc@eZdZdZdZdddZdS) _ResultMixinStrz>Standard approach to encoding parsed results from str to bytesr;r>r?c|jfdd|DS)Nc3|] }|VqdSr@rCrKrNr;r<rO~z)_ResultMixinStr.encode..)_encoded_counterpartselfrErFr;rNr<rD}z_ResultMixinStr.encodeNr>r?)__name__ __module__ __qualname____doc__ __slots__rDr;r;r;r<rZyrZc@rY) _ResultMixinBytesz>Standard approach to decoding parsed results from bytes to strr;r>r?cr[)Nc3r\r@rIrKrNr;r<rOr]z+_ResultMixinBytes.decode..)_decoded_counterpartr_r;rNr<rJraz_ResultMixinBytes.decodeNrb)rcrdrerfrgrJr;r;r;r<rirhric@sDeZdZdZdZeddZeddZeddZed d Z d S) _NetlocResultMixinBasezHShared methods for the parsed result objects containing a netloc elementr;cC |jdSNr _userinfor`r;r;r<username z_NetlocResultMixinBase.usernamecCrl)NrSrnrpr;r;r<passwordrrz_NetlocResultMixinBase.passwordcCs*|jd}|s d}|S|dur|}|Srm) _hostinfolower)r`hostnamer;r;r<rvs z_NetlocResultMixinBase.hostnamecCs<|jd}|durt|d}d|krdksdSdS|S)NrS ri)rtr)r`portr;r;r<rxs  z_NetlocResultMixinBase.portN) rcrdrerfrgpropertyrqrsrvrxr;r;r;r<rks   rkc@(eZdZdZeddZeddZdS)_NetlocResultMixinStrr;cCJ|j}|d\}}}|r|d\}}}|sd}||fSd}}||fS)N@:netloc rpartition partitionr`ruserinfo have_infohostinforq have_passwordrsr;r;r<roz_NetlocResultMixinStr._userinfoc Cl|j}|d\}}}|d\}}}|r&|d\}}}|d\}}}n|d\}}}|s2d}||fS)Nr}[]r~r r`r_r have_open_br bracketedrvrx have_portr;r;r<rtz_NetlocResultMixinStr._hostinfoNrcrdrergryrortr;r;r;r<r{   r{c@rz)_NetlocResultMixinBytesr;cCr|)N@:rrr;r;r<rorz!_NetlocResultMixinBytes._userinfoc Cr)Nr[]rrrr;r;r<rtrz!_NetlocResultMixinBytes._hostinfoNrr;r;r;r<rrr) namedtuple DefragResultz url fragment SplitResultz!scheme netloc path query fragment ParseResultz(scheme netloc path params query fragmentc@eZdZdZddZdS)rr;cC|jr |jd|jS|jS)N#fragmenturlrpr;r;r<geturlzDefragResult.geturlNrcrdrergrr;r;r;r<r c@r)rr;cCt|Sr@rrpr;r;r<rzSplitResult.geturlNrr;r;r;r<rrc@r)rr;cCrr@r rpr;r;r<rrzParseResult.geturlNrr;r;r;r<rrc@r)DefragResultBytesr;cCr)N#rrpr;r;r<rrzDefragResultBytes.geturlNrr;r;r;r<rrrc@r)SplitResultBytesr;cCrr@rrpr;r;r<rrzSplitResultBytes.geturlNrr;r;r;r<r rrc@r)ParseResultBytesr;cCrr@rrpr;r;r<rrzParseResultBytes.geturlNrr;r;r;r<rrrcCs4ttfttfttff}|D] \}}||_||_q dSr@)rrrrrrr^rj) _result_pairs_decoded_encodedr;r;r<_fix_result_transcodings rr(Tc Csft||\}}}t|||}|\}}}}}|tvr$d|vr$t|\}}nd}t||||||} || S)a#Parse a URL into 6 components: :///;?# 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 splitresultrqueryrparamsresultr;r;r<r $s r cCsRd|vr|d|d}|dkr|dfSn|d}|d|||ddfS)N/rrr(rS)findrfind)rir;r;r<r4s rcCsHt|}dD]}|||}|dkrt||}q|||||dfS)Nz/?#r)lenrmin)rstartdelimcwdelimr;r;r< _splitnetloc=s  rc Cs6t||\}}}t|}|||t|t|f}t|d}|r#||Stttkr,td}}}|d} | dkr|d| dkr|d|  }|| dd}|dddkrvt |d\}}d |vrjd |vsrd |vrvd |vrvt d |rd |vr| d d\}}d |vr| d d\}}t |||||} | t|<|| S|d| D]} | tvrnq|| dd} | rtdd| Dr|d|  | }}|dddkrt |d\}}d |vrd |vsd |vrd |vrt d |rd |vr| d d\}}d |vr | 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(r~rrrS//rrzInvalid IPv6 URLr?css|]}|dvVqdS) 0123456789Nr;rLrr;r;r<rOlszurlsplit..)rXbooltyper8getrMAX_CACHE_SIZEr=rrur ValueErrorsplitr scheme_charsany) rrrrkeycachedrrrrvrrestr;r;r<rEsZ       rcCs<t|\}}}}}}}|rd||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) componentsrrrrrrrr;r;r<r }s  r cCst|\}}}}}}|s|r0|tvr0|dddkr0|r(|dddkr(d|}d|p,d|}|r8|d|}|r@|d|}|rH|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(r~rr)rX uses_netloc)rrrrrrrr;r;r<rs    rcCs|s|S|s|St||\}}}t|d|\}}}}}} t|||\} } } } }}| |ks0| tvr4||S| tvrH| rF|t| | | | ||fS|} | dddkr\|t| | | | ||fS| st| st|} |} |sh|}|t| | | | ||fS|ddd| d}|ddkrd|d<d|vr|dd|vs d}t|d}||kr||dkr||ddvr||d|d=n |d}||ksnq|ddgkrd|d<nt|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 bfragmentrrpathrrrsegmentsrnr;r;r<rsl          rc CsTt|\}}d|vrt|\}}}}}}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 r0123456789ABCDEFabcdefccs:|]}tD]}||tt||dgfVqqdS)N)_hexdigrDrr)rLrbr;r;r<rOs *rOc Cs|s |jtdSt|tr|d}t|}|d}t|dkr$|S|dg}|j}|ddD]'}z|t|dd||ddWq2tyY|d||Yq2wtd |S)z,unquote_to_bytes('abc%20def') -> b'abc def'.utf-8%rSrNr) rrrTr rDrappend _hextobyteKeyErrorr)stringbitsresritemr;r;r<rs(       rz([-]+)rreplacecCsd|vr |j|S|durd}|durd}t|}|dg}|j}tdt|dD]}|t|||||||dq*d|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 rrrJr)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. rN)rr) qskeep_blank_valuesstrict_parsingrErF parsed_resultpairsnamevaluer;r;r<rs  rc Cst|\}}dd|dD}g}|D]Z}|s|sq|dd} t| dkr9|r0td|f|r8| dnqt| dsA|rn| 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]}|q qS)rr)rLs1s2r;r;r< Ts zparse_qsl..&=rSrzbad query field: %rr(r+ rN)rXrrrrrr) rrrrErFrrr name_valuenvrr r;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 )rrpr;r;r<__repr__rHzQuoter.__repr__cCs(||jvr t|nd|}|||<|S)Nz%{0:02X})rrformat)r`rrr;r;r< __missing__szQuoter.__missing__N)rcrdrerfrrrr;r;r;r<r|s  rrcCsbt|tr|s |S|durd}|durd}|||}n|dur$td|dur,tdt||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|tr d|vst|trd|vrt||||St|tr#td}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|ttfs td|stdSt|}t|tr#t|dd}n t|}tdd|D}|t|s;|Szt |Wnt ySt |j t |<Ynwtd 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<r sz$quote_from_bytes..csg|]}|qSr;r;)rLcharquoterr;r<r s)rTr bytearrayrUr rDrstrip_ALWAYS_SAFE_BYTESrJr:rr __getitem__r)bsrr;r"r<rs"   rc Cst|dr |}n'zt|rt|dtstWnty0t\}}}ttd|Ynwg}|sn|D]5\} } t| t rFt | |} n t t | |||} t| t rZt | |} n t t | |||} | | d| q7n|D]\} } t| t rt | |} n t t | |||} t| t rt | |} | | d| qpt| t rt | |||} | | d| qpzt| } Wntyt t | |||} | | d| Yqpw| D]} t| t rt | |} n t t | |||} | | d| qqpt 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)hasattrr)rrTrPrUsysexc_infor rrr rr) rdoseqrrErFtyvatblkrrMeltr;r;r<rs\                 rcCsFt|tr!z |d}W|Sty tdt|dw|S)zto_bytes(u"URL") --> 'URL'.ASCIIzURL z contains non-ASCII characters)rTr rDrJ UnicodeErrorreprrr;r;r<to_bytesHs  r8cCs`t|}|dddkr|dddkr|dd}|dddkr.|dd}|S)z8unwrap('') --> 'type://host/path'.NrSzURL:)r stripr7r;r;r<unwrapUs   r=cCsVtdur ddl}|dat|}|r'|d}||t|ddfSd|fS)z:splittype('type:opaquestring') --> 'type', 'opaquestring'.Nrz ^([^/:]+):rS) _typeprogrecompilematchgrouprur)rr?rArr;r;r< splittype^s   rCcCsbtdur ddl}|dat|}|r-|d}|d}|r)|ds)d|}||fSd|fS)z;splithost('//host[:port]/path') --> 'host[:port]', '/path'.Nrz^//([^/?]*)(.*)$rSrr) _hostprogr?r@rArB startswith)rr?rA host_portrr;r;r< splithostls    rGcCs<tdur ddl}|dat|}|r|ddSd|fS)zJsplituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.Nrz ^(.*)@(.*)$rSr) _userprogr?r@rArBhostr?rAr;r;r< splituser}   rKcCs@tdurddl}|d|jat|}|r|ddS|dfS)z/splitpasswd('user:passwd') -> 'user', 'passwd'.Nrz^([^:]*):(.*)$rSr) _passwdprogr?r@SrArB)userr?rAr;r;r< splitpasswds  rPcC<tdur ddl}|dat|}|r|ddS|dfS)z*splitport('host:port') --> 'host', 'port'.Nrz^(.*):([0-9]+)$rSr) _portprogr?r@rArBrIr;r;r< splitportrLrSrcCs|tdur ddl}|dat|}|r:|dd\}}z|s#tdt|}W||fSty9d}Y||fSw||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@rArBrr)rJdefportr?rArxnportr;r;r< splitnports     rWcCrQ)z/splitquery('/path?query') --> '/path', 'query'.Nrz^(.*)\?([^?]*)$rSr) _queryprogr?r@rArBrr?rAr;r;r< splitqueryrLrZcCrQ)z)splittag('/path#tag') --> '/path', 'tag'.Nrz^(.*)#([^#]*)$rSr)_tagprogr?r@rArBrYr;r;r<splittagrLr\cCs|d}|d|ddfS)zksplitattr('/path;attr1=value1;attr2=value2;...') -> '/path', ['attr1=value1', 'attr2=value2', ...].rrrSNr )rwordsr;r;r< splitattrs r^cCrQ)z-splitvalue('attr=value') --> 'attr', 'value'.Nrz^([^=]*)=(.*)$rSr) _valueprogr?r@rArB)attrr?rAr;r;r< splitvaluerLra)r(T)r)T)rr)FFrr)rNN)r(NN)r)Fr(NN)r)drf __future__rrrfuture.builtinsrrrrr r future.utilsr r?r+ collections__all__rrrnon_hierarchical uses_query uses_fragmentrrr8r=_implicit_encoding_implicit_errorsrBrGrRrXobjectrZrirkr{rr_DefragResultBase_SplitResultBase_ParseResultBase ResultBaserrrrrrrr rrrr rrrrrrr@rrrrr frozensetrr&r: defaultdictrrrrrr8r=r>rCrDrGrHrKrMrPrRrSrTrWrXrZr[r\r^r_rar;r;r;r<s             8 5     0   ,  ]