e fX@sdZddlZddlZddlZddddddd d d d d ddddgZddddddddddddddd d!d"gZddddd#ddddddd$dddd%dd!d"d d&d'd(gZdd)dddddddd*d+ddd d,gZdd)d-d.d#ddd$d*d+g Zdddddddddd*d+dg Z dd)ddd.ddddd$dddg Z d/Z d0Z iZ d1d2Zd3Zd4Zd5d6Zeed7d8Zeed9d:Zd;d<ZGd=d>d>eZGd?d@d@eZGdAdBdBeZGdCdDdDeeZGdEdFdFeeZddGlmZedHdIZedJdKZedLdMZeZGdNdHdHeeZ GdOdJdJeeZ!GdPdLdLeeZ"GdQdRdReeZ#GdSdTdTeeZ$GdUdVdVeeZ%dWdXZ&e&[&ddYdZdZ'd[d\Z(dd]d^Z)d_d`Z*ddYdadZ+dbdZ,dcdZ-dYdddZ.dedZ/dfZ0da1dgdZ2ej3dhZ4didjdkdZ5dldldidjdmd Z6dldldidjdnd Z7didjdodZ8e9dpZ:e;e:Z<iZ=Gdqdrdrej>Z?dsdddtd Z@ddddud ZAdsdvdZBdlddddwd ZCdxdyZDdzd{ZEdaFd|d}ZGdaHd~dZIdaJddZKdaLddZMdaNddZOdaPdddZQdaRddZSdaTddZUddZVdaWddZXdS)acParse (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. Nurlparse urlunparseurljoin urldefragurlsplit urlunsplit urlencodeparse_qs parse_qslquote quote_plusquote_from_bytesunquote unquote_plusunquote_to_bytesZftphttpZgopherZnntpZimapZwaisfileZhttpsZshttpZmmsZprosperoZrtspZrtspuZsftpZsvnzsvn+sshZtelnetZsnewsZrsyncZnfsZgitzgit+sshZhdlZsipZsipsZtelZmailtoZnewszAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.cCstjtjdS)z,Clear the parse cache and the quoters cache.N) _parse_cacheclear _safe_quotersrr1/opt/alt/python34/lib64/python3.4/urllib/parse.py clear_cacheHs rasciistrictcCs|S)Nr)objrrr_noopWsrcCs|j||S)N)encode)rencodingerrorsrrr_encode_resultZsr"cs tfdd|DS)Nc3s-|]#}|r!|jndVqdS)rN)decode).0x)r r!rr `sz_decode_args..)tuple)argsr r!r)r r!r _decode_args^sr)cGszt|dt}xB|ddD]0}|r$t|t|kr$tdq$q$W|ri|tfSt|tfS)Nrz$Cannot mix str and non-str arguments) isinstancestr TypeErrorrr)r")r(Z str_inputargrrr _coerce_argsbs r/c@s.eZdZdZfZddddZdS)_ResultMixinStrz>Standard approach to encoding parsed results from str to bytesrrcs#|jfdd|DS)Nc3s!|]}|jVqdS)N)r)r$r%)r r!rrr&xsz)_ResultMixinStr.encode..)_encoded_counterpart)selfr r!r)r r!rrwsz_ResultMixinStr.encodeN)__name__ __module__ __qualname____doc__ __slots__rrrrrr0ss r0c@s.eZdZdZfZddddZdS)_ResultMixinBytesz>Standard approach to decoding parsed results from bytes to strrrcs#|jfdd|DS)Nc3s!|]}|jVqdS)N)r#)r$r%)r r!rrr&sz+_ResultMixinBytes.decode..)_decoded_counterpart)r2r r!r)r r!rr#sz_ResultMixinBytes.decodeN)r3r4r5r6r7r#rrrrr8{s r8c@sdeZdZdZfZeddZeddZeddZedd Z d S) _NetlocResultMixinBasezHShared methods for the parsed result objects containing a netloc elementcCs |jdS)Nr) _userinfo)r2rrrusernamesz_NetlocResultMixinBase.usernamecCs |jdS)Nr*)r;)r2rrrpasswordsz_NetlocResultMixinBase.passwordcCs;|jd}|sd}n|dk r7|j}n|S)Nr) _hostinfolower)r2hostnamerrrr@s    z_NetlocResultMixinBase.hostnamecCsO|jd}|dk rKt|d}d|ko?dknsKdSn|S)Nr* ri)r>int)r2portrrrrCs   z_NetlocResultMixinBase.portN) r3r4r5r6r7propertyr<r=r@rCrrrrr:s  r:c@s:eZdZfZeddZeddZdS)_NetlocResultMixinStrcCse|j}|jd\}}}|rQ|jd\}}}|s[d}q[n d}}||fS)N@:)netloc rpartition partition)r2rHuserinfo have_infohostinfor< have_passwordr=rrrr;s   z_NetlocResultMixinStr._userinfocCs|j}|jd\}}}|jd\}}}|rr|jd\}}}|jd\}}}n|jd\}}}|sd}n||fS)NrF[]rG)rHrIrJ)r2rH_rM have_open_br bracketedr@rCrrrr>s  z_NetlocResultMixinStr._hostinfoN)r3r4r5r7rDr;r>rrrrrEs  rEc@s:eZdZfZeddZeddZdS)_NetlocResultMixinBytescCse|j}|jd\}}}|rQ|jd\}}}|s[d}q[n d}}||fS)N@:)rHrIrJ)r2rHrKrLrMr<rNr=rrrr;s   z!_NetlocResultMixinBytes._userinfocCs|j}|jd\}}}|jd\}}}|rr|jd\}}}|jd\}}}n|jd\}}}|sd}n||fS)NrU[]rV)rHrIrJ)r2rHrQrMrRrSr@rCrrrr>s  z!_NetlocResultMixinBytes._hostinfoN)r3r4r5r7rDr;r>rrrrrTs  rT) namedtuple DefragResultz url fragment SplitResultz!scheme netloc path query fragment ParseResultz(scheme netloc path params query fragmentc@s"eZdZfZddZdS)rZcCs&|jr|jd|jS|jSdS)N#)fragmenturl)r2rrrgeturls zDefragResult.geturlN)r3r4r5r7r`rrrrrZs c@s"eZdZfZddZdS)r[cCs t|S)N)r)r2rrrr`szSplitResult.geturlN)r3r4r5r7r`rrrrr[s c@s"eZdZfZddZdS)r\cCs t|S)N)r)r2rrrr`szParseResult.geturlN)r3r4r5r7r`rrrrr\s c@s"eZdZfZddZdS)DefragResultBytescCs&|jr|jd|jS|jSdS)N#)r^r_)r2rrrr`s zDefragResultBytes.geturlN)r3r4r5r7r`rrrrras rac@s"eZdZfZddZdS)SplitResultBytescCs t|S)N)r)r2rrrr`szSplitResultBytes.geturlN)r3r4r5r7r`rrrrrcs rcc@s"eZdZfZddZdS)ParseResultBytescCs t|S)N)r)r2rrrr` szParseResultBytes.geturlN)r3r4r5r7r`rrrrrd s rdcCsNttfttfttff}x&|D]\}}||_||_q(WdS)N)rZrar[rcr\rdr1r9)Z _result_pairsZ_decodedZ_encodedrrr_fix_result_transcodings    reTc Cst||\}}}t|||}|\}}}}}|tkrld|krlt|\}}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)r/r uses_params _splitparamsr\) r_schemeallow_fragments_coerce_resultZ splitresultrHqueryr^paramsresultrrrrscCsqd|kr@|jd|jd}|dkrO|dfSn|jd}|d|||ddfS)N/rfrrr*)findrfind)r_irrrrh.s    rhcCskt|}x>dD]6}|j||}|dkrt||}qqW|||||dfS)Nz/?#r)lenrpmin)r_startZdelimcZwdelimrrr _splitnetloc7s    rwcCs| s!tdd|D r%dSddl}|jd|}||krSdS|jd\}}}x5dD]-}||krrtd|dd qrqrWdS) Ncss!|]}t|dkVqdS)N)ord)r$rvrrrr&@sz_checknetloc..rZNFKCrFz/?#@:znetloc 'z' contains invalid z#characters under NFKC normalization)any unicodedataZ normalizerI ValueError)rHr{Znetloc2rQrvrrr _checknetloc?s!    r}c Cs\t||\}}}t|}|||t|t|f}tj|d}|rg||Stttkrtnd}}}|jd} | dkre|d| dkr|d| j }|| dd}|dddkrYt |d\}}d |kr/d |ksGd |krYd |krYt d qYn|rd |kr|j d d\}}nd |kr|j d d\}}nt |t|||||} | t|<|| Sx|d| D]} | tkrPqqW|| dd} | sBtdd| Dre|d| j | }}qen|dddkrt |d\}}d |krd |ksd |krd |krt d qn|rd |kr|j d d\}}nd |kr&|j d d\}}nt |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.NrrGrrr*z//rOrPzInvalid IPv6 URLr]?css|]}|dkVqdS) 0123456789Nr)r$rvrrrr&vszurlsplit..)r/booltypergetrsMAX_CACHE_SIZErrpr?rwr|splitr}r[ scheme_charsrz) r_rirjrkkeycachedrHrlr^rrvrvrestrrrrNs\ !         #   cCsYt|\}}}}}}}|r:d||f}n|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)r/r) componentsrirHr_rmrlr^rkrrrrs!cCst|\}}}}}}|sL|r|tkr|dddkr|ru|dddkrud|}nd|pd|}n|r|d|}n|r|d|}n|r|d |}n||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).Nr~z//r*rorrGrr])r/ uses_netloc)rrirHr_rlr^rkrrrrs. cCs|s |S|s|St||\}}}t|d|\}}}}}} t|||\} } } } }}| |ks| tkr||S| tkr| r|t| | | | ||fS|} n| dddkr |t| | | | ||fS| rV| rV|} |} |s4|}n|t| | | | ||fS|jddd| jd}|d dkrd|d b'abc def'.zutf-8%r*rNcSsFi|]<}tD]/}tt||dg||jqqS))_hexdigbytesrBr)r$rbrrr s z$unquote_to_bytes..r~) rr+r,rrsappend _hextobyterKeyErrorr)stringbitsresritemrrrrs*       z([-]+)zutf-8replacecCsd|kr|j|S|dkr,d}n|dkrAd}ntj|}|dg}|j}xRtdt|dD]8}|t||j|||||dqWdj|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'. %Nzutf-8rrr*r~r)r_asciirerrangersrr#r)rr r!rrrrrrrrrs        Fc Csli}t|||d|d|}xA|D]9\}}||krW||j|q+|g||_s zparse_qsl..&=r*r~zbad query field: %rrr+ r r!)r/rrsr|rrr) rrrr r!rkrrZ name_valueZnvrrrrrr Gs,   cCs"|jdd}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)rr r!rrrrwssAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-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). cCstj||_dS)zsafe: bytes object.N) _ALWAYS_SAFEunionsafe)r2rrrr__init__szQuoter.__init__cCsdt|S)Nz )dict)r2rrr__repr__szQuoter.__repr__cCs8||jkrt|n dj|}|||<|S)Nz%{:02X})rchrformat)r2rrrrr __missing__s* zQuoter.__missing__N)r3r4r5r6rrrrrrrrs   rrocCst|trX|s|S|dkr.d}n|dkrCd}n|j||}n6|dk rstdn|dk rtdnt||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 and errors must not be specified if string is a bytes object. 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). Nzutf-8rz,quote() doesn't support 'encoding' for bytesz*quote() doesn't support 'errors' for bytes)r+r,rr-r )rrr r!rrrr s      cCst|trd|ks6t|trId|krIt||||St|trad}nd}t|||||}|jddS)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)r+r,rr r)rrr r!Zspacerrrr s c st|ttfs$tdn|s.dSt|trR|jdd}ntdd|D}|jt|s|jSyt |Wn)t k rt |j t |<YnXdj 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 bytesrrignorecSs"g|]}|dkr|qS)r)r$rvrrrrs z$quote_from_bytes..csg|]}|qSrr)r$char)quoterrrrs )r+r bytearrayr-r,rrstrip_ALWAYS_SAFE_BYTESr#rrr __getitem__r)Zbsrr)rrr s  c Cst|dr|j}nly-t|rJt|dt rJtnWn<tk rtj\}}}tdj|YnXg}|s=x |D]\} } t| t rt | |} nt t | |||} t| t rt | |} nt t | |||} |j | d| qWn|xy|D]q\} } t| t rqt | |} nt t | |||} t| t rt | |} |j | d| qDt| t rt | |||} |j | d| qDyt| } WnBtk rRt t | |||} |j | d| YqDXx_| D]W} t| t rt | |} nt t | |||} |j | d| qZWqDWdj |S)aGEncode a dict or sequence of two-element tuples 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 components of a query arg may each be either a string or a bytes type. The safe, encoding, and errors parameters are passed down to quote_plus() (encoding and errors only if a component is a str). itemsrz1not a valid non-string sequence or mapping objectrr)hasattrrrsr+r'r-sysexc_infowith_tracebackrr r,rr) rlZdoseqrr r!ZtyZvatblkrr%ZeltrrrrsP      c Cs^t|trZy|jdj}WqZtk rVtdt|dYqZXn|S)zto_bytes(u"URL") --> 'URL'.ASCIIzURL z contains non-ASCII characters)r+r,rr# UnicodeErrorrepr)r_rrrto_bytesNs rcCst|j}|dddkrW|dddkrW|ddj}n|dddkr|ddj}n|S) z8unwrap('') --> 'type://host/path'.Nr*<>zURL:rr)r,strip)r_rrrunwrap[s ,rcCsptdkrtjdantj|}|rf|jd}|j|t|ddfSd|fS)z:splittype('type:opaquestring') --> 'type', 'opaquestring'.Nz ^([^/:]+):r*) _typeprogrecompilematchgroupr?rs)r_rrirrr splittypeds $rcCstdkr$tjdtjantj|}|r|jd}|jd}|rz|jd rzd|}n||fSd|fS)z;splithost('//host[:port]/path') --> 'host[:port]', '/path'.Nz//([^/#?]*)(.*)r*r~ro) _hostprogrrDOTALLrr startswith)r_rZ host_portrrrr splithostqs   rcCsMtdkrtjdantj|}|rC|jddSd|fS)zJsplituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.Nz ^(.*)@(.*)$r*r~) _userprogrrrr)hostrrrr splitusers  rcCsStdkr$tjdtjantj|}|rI|jddS|dfS)z/splitpasswd('user:passwd') -> 'user', 'passwd'.Nz^([^:]*):(.*)$r*r~) _passwdprogrrSrr)userrrrr splitpasswds  rcCsbtdkrtjdantj|}|rX|j\}}|rX||fSn|dfS)z*splitport('host:port') --> 'host', 'port'.Nz^(.*):([0-9]*)$) _portprogrrrgroups)rrrCrrr splitports  rr*c Cstdkrtjdantj|}|r|jdd\}}|ryt|}Wntk r{d}YnX||fSn||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.Nz ^(.*):(.*)$r*r~) _nportprogrrrrrBr|)rZdefportrrCZnportrrr splitnports    rcCsMtdkrtjdantj|}|rC|jddS|dfS)z/splitquery('/path?query') --> '/path', 'query'.Nz^(.*)\?([^?]*)$r*r~) _queryprogrrrr)r_rrrr splitquerys  rcCsMtdkrtjdantj|}|rC|jddS|dfS)z)splittag('/path#tag') --> '/path', 'tag'.Nz^(.*)#([^#]*)$r*r~)_tagprogrrrr)r_rrrrsplittags  rcCs'|jd}|d|ddfS)zksplitattr('/path;attr1=value1;attr2=value2;...') -> '/path', ['attr1=value1', 'attr2=value2', ...].rfrr*N)r)r_Zwordsrrr splitattrsrcCsMtdkrtjdantj|}|rC|jddS|dfS)z-splitvalue('attr=value') --> 'attr', 'value'.Nz^([^=]*)=(.*)$r*r~) _valueprogrrrr)attrrrrr splitvalues  rr)Yr6rr collections__all__rrrgZnon_hierarchicalZ uses_queryZ uses_fragmentrrrrZ_implicit_encodingZ_implicit_errorsrr"r)r/objectr0r8r:rErTrYZ_DefragResultBaseZ_SplitResultBaseZ_ParseResultBaseZ ResultBaserZr[r\rarcrdrerrhrwr}rrrrrrrrrrrr r r frozensetrrrr defaultdictrr r r rrrrrrrrrrrrrrrrrrrrrrrrrrs               : 5  /  ,^