Yf!@sdZddlZddlZddlZddddddd d d d d ddddddddddgZddddddddd d!d"d#d$d%d&d'd(d)d*gZdddddd+dddd"d d!d,d#d$d%d-d'd(d&d.d/d0d)d*gZddd1d#ddd d!d$d%d2d3d"d&d4gZdd1d5d6d+ddd,d2d3g Zddddd d!d"dd$d%d2d3g Z ddd1ddd6ddd d!d,dd#g Z d7Z d8Z iZ d9d:Zd;Zd<Zd=d>Zeed?d@ZeedAdBZdCdDZGdEdFdFeZGdGdHdHeZGdIdJdJeZGdKdLdLeeZGdMdNdNeeZddOlmZeddPZeddQZeddRZeZGdSddeeZ GdTddeeZ!GdUddeeZ"GdVddeeZ#GdWddeeZ$GdXddeeZ%dYdZZ&e&[&dd[d\dZ'd]d^Z(dd_d`Z)dadbZ*dd[dcdZ+dddZ,dedZ-d[dfdZ.dgdZ/dhZ0da1didZ2ej3djZ4dkdldmdZ5dndndkdldod Z6dndndkdldpd Z7dkdldqdZ8e9drZ:e;e:Z<iZ=Gdsdtdtej>Z?dudddvd Z@ddddwd ZAdudxdZBdndddeAdyd ZCdzd{ZDd|d}ZEdaFd~dZGdaHddZIddZJddZKdaLddZMdddZNddZOddZPddZQddZRdS)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_bytes DefragResult ParseResult SplitResultDefragResultBytesParseResultBytesSplitResultBytesZftphttpZgopherZnntpZimapZwaisfileZhttpsZshttpZmmsZprosperoZrtspZrtspuZsftpZsvnzsvn+sshZwsZwssZtelnetZsnewsZrsyncZnfsZgitzgit+sshZhdlZsipZsipsZtelZmailtoZnewszAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.cCstjtjdS)z,Clear the parse cache and the quoters cache.N) _parse_cacheclear _safe_quotersrr1/opt/alt/python35/lib64/python3.5/urllib/parse.py clear_cacheSs r asciistrictcCs|S)Nr)objrrr_noopbsr$cCs|j||S)N)encode)r#encodingerrorsrrr_encode_resultesr(cs tfdd|DS)Nc3s-|]#}|r!|jndVqdS)rN)decode).0x)r&r'rr ksz_decode_args..)tuple)argsr&r'r)r&r'r _decode_argsisr/cGswt|dt}x?|ddD]-}|r$t|t|kr$tdq$W|rf|tfSt|tfS)Nrz$Cannot mix str and non-str arguments) isinstancestr TypeErrorr$r/r()r.Z str_inputargrrr _coerce_argsms r5c@s.eZdZdZfZddddZdS)_ResultMixinStrz>Standard approach to encoding parsed results from str to bytesr!r"cs#|jfdd|DS)Nc3s!|]}|jVqdS)N)r%)r*r+)r&r'rrr,sz)_ResultMixinStr.encode..)_encoded_counterpart)selfr&r'r)r&r'rr%sz_ResultMixinStr.encodeN)__name__ __module__ __qualname____doc__ __slots__r%rrrrr6~s r6c@s.eZdZdZfZddddZdS)_ResultMixinBytesz>Standard approach to decoding parsed results from bytes to strr!r"cs#|jfdd|DS)Nc3s!|]}|jVqdS)N)r))r*r+)r&r'rrr,sz+_ResultMixinBytes.decode..)_decoded_counterpart)r8r&r'r)r&r'rr)sz_ResultMixinBytes.decodeN)r9r:r;r<r=r)rrrrr>s r>c@sdeZdZdZfZeddZeddZeddZedd Z d S) _NetlocResultMixinBasezHShared methods for the parsed result objects containing a netloc elementcCs |jdS)Nr) _userinfo)r8rrrusernamesz_NetlocResultMixinBase.usernamecCs |jdS)Nr0)rA)r8rrrpasswordsz_NetlocResultMixinBase.passwordcCs8|jd}|sd}n|dk r4|j}|S)Nr) _hostinfolower)r8hostnamerrrrFs     z_NetlocResultMixinBase.hostnamecCsL|jd}|dk rHt|d}d|ko?dknsHdS|S)Nr0 ri)rDint)r8portrrrrIs   z_NetlocResultMixinBase.portN) r9r:r;r<r=propertyrBrCrFrIrrrrr@s  r@c@s:eZdZfZeddZeddZdS)_NetlocResultMixinStrcCsb|j}|jd\}}}|rN|jd\}}}|sXd}n d}}||fS)N@:)netloc rpartition partition)r8rNuserinfo have_infohostinforB have_passwordrCrrrrAs   z_NetlocResultMixinStr._userinfocCs|j}|jd\}}}|jd\}}}|rr|jd\}}}|jd\}}}n|jd\}}}|sd}||fS)NrL[]rM)rNrOrP)r8rN_rS have_open_br bracketedrFrIrrrrDs z_NetlocResultMixinStr._hostinfoN)r9r:r;r=rJrArDrrrrrKs  rKc@s:eZdZfZeddZeddZdS)_NetlocResultMixinBytescCsb|j}|jd\}}}|rN|jd\}}}|sXd}n d}}||fS)N@:)rNrOrP)r8rNrQrRrSrBrTrCrrrrAs   z!_NetlocResultMixinBytes._userinfocCs|j}|jd\}}}|jd\}}}|rr|jd\}}}|jd\}}}n|jd\}}}|sd}||fS)Nr[[]r\)rNrOrP)r8rNrWrSrXrYrFrIrrrrDs z!_NetlocResultMixinBytes._hostinfoN)r9r:r;r=rJrArDrrrrrZs  rZ) namedtuplez url fragmentz!scheme netloc path query fragmentz(scheme netloc path params query fragmentc@s"eZdZfZddZdS)rcCs&|jr|jd|jS|jSdS)N#)fragmenturl)r8rrrgeturls zDefragResult.geturlN)r9r:r;r=rcrrrrrs c@s"eZdZfZddZdS)rcCs t|S)N)r)r8rrrrcszSplitResult.geturlN)r9r:r;r=rcrrrrrs c@s"eZdZfZddZdS)rcCs t|S)N)r)r8rrrrcszParseResult.geturlN)r9r:r;r=rcrrrrrs c@s"eZdZfZddZdS)rcCs&|jr|jd|jS|jSdS)N#)rarb)r8rrrrc s zDefragResultBytes.geturlN)r9r:r;r=rcrrrrr s c@s"eZdZfZddZdS)rcCs t|S)N)r)r8rrrrcszSplitResultBytes.geturlN)r9r:r;r=rcrrrrrs c@s"eZdZfZddZdS)rcCs t|S)N)r)r8rrrrcszParseResultBytes.geturlN)r9r:r;r=rcrrrrrs cCsNttfttfttff}x&|D]\}}||_||_q(WdS)N)rrrrrrr7r?)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)r5r uses_params _splitparamsr) rbschemeallow_fragments_coerce_resultZ splitresultrNqueryraparamsresultrrrr)scCsqd|kr@|jd|jd}|dkrO|dfSn|jd}|d|||ddfS)N/rfrrr0)findrfind)rbirrrrh9s    rhcCsht|}x;dD]3}|j||}|dkrt||}qW|||||dfS)Nz/?#r)lenrpmin)rbstartdelimcZwdelimrrr _splitnetlocBs    rxcCs| s!tdd|D r%dSddl}|jdd}|jdd}|jdd}|jdd}|jd |}||krdSx2d D]*}||krtd |d d qWdS)Ncss!|]}t|dkVqdS)N)ord)r*rwrrrr,Ksz_checknetloc..rrLrrMr`?ZNFKCz/?#@:znetloc 'z' contains invalid z#characters under NFKC normalization)any unicodedatareplaceZ normalize ValueError)rNr}nZnetloc2rwrrr _checknetlocJs!    rc Cs8t||\}}}t|}|||t|t|f}tj|d}|rg||Stttkrtd}}}|jd} | dkrM|d| dkr|d| j }|| dd}|dddkrPt |d\}}d |kr,d |ksDd |krPd |krPt d |rzd |krz|j d d\}}d |kr|j d d\}}t |t|||||} | t|<|| Sxv|d| D]} | tkrPqW|| dd} | s0tdd| DrM|d| j | }}|dddkrt |d\}}d |krd |ksd |krd |krt d |rd |kr|j d d\}}d |kr|j d d\}}t |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.NrrMrrr0z//rUrVzInvalid IPv6 URLr`r{css|]}|dkVqdS) 0123456789Nr)r*rwrrrr,szurlsplit..)r5booltypergetrsMAX_CACHE_SIZEr rprErxrsplitrr scheme_charsr|) rbrirjrkkeycachedrNrlrarrvrwrestrrrr\s\ !             cCsVt|\}}}}}}}|r7d||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)r5r) componentsrirNrbrmrlrarkrrrrs!cCst|\}}}}}}|sL|r|tkr|dddkr|rr|dddkrrd|}d|p~d|}|r|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).Nrz//r0rorrMr{r`)r5 uses_netloc)rrirNrbrlrarkrrrrs. c CsR|s |S|s|St||\}}}t|d|\}}}}}} t|||\} } } } }}| |ks| tkr||S| tkr| r|t| | | | ||fS|} | r| r|} |} |s|}|t| | | | ||fS|jd}|ddkr>|d=| dddkrf| jd}n6|| jd}td|dd |dd  b'abc def'.zutf-8%r0rNcSsFi|]<}tD]/}tt||dg||jqqS))_hexdigbytesrHr%)r*rbrrr s z$unquote_to_bytes..r) rr1r2r%rsr _hextobyterKeyErrorr)stringbitsresritemrrrr s*       z([-]+)zutf-8r~cCsd|kr|j|S|dkr)d}|dkr;d}tj|}|dg}|j}xRtdt|dD]8}|t||j|||||dqyWdj|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-8r~rr0rr)r_asciirerrangersrr)r)rr&r'rrrrrrrrr,s      Fc Csli}t|||d|d|}xA|D]9\}}||krW||j|q+|g||s zparse_qsl..&=r0rzbad query field: %rrr+ r&r')r5rrsrrr~r) rrrr&r'rkrrZ name_valueZnvrrrrrr is,   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)r~r)rr&r'rrrrssAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-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)r8rrrr__init__szQuoter.__init__cCsd|jjt|fS)Nz<%s %r>) __class__r9dict)r8rrr__repr__szQuoter.__repr__cCs8||jkrt|n dj|}|||<|S)Nz%{:02X})rchrformat)r8rrrrr __missing__s* zQuoter.__missing__N)r9r:r;r<rrrrrrrrs   rrocCst|trR|s|S|dkr+d}|dkr=d}|j||}n0|dk rjtd|dk rtdt||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-8r"z,quote() doesn't support 'encoding' for bytesz*quote() doesn't support 'errors' for bytes)r1r2r%r3r )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)r1r2rr r~)rrr&r'Zspacerrrr s c st|ttfs!td|s+dSt|trO|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 bytesrr!ignorecSs"g|]}|dkr|qS)r)r*rwrrrr s z$quote_from_bytes..csg|]}|qSrr)r*char)quoterrrrs )r1r bytearrayr3r2r%rstrip_ALWAYS_SAFE_BYTESr)rrr __getitem__r)Zbsrr)rrr s   cCst|dr|j}niy*t|rGt|dt rGtWn<tk rtj\}}}tdj|YnXg} |s:x |D]\} } t| t r|| |} n|t | |||} t| t r|| |} n|t | |||} | j | d| qWn|xy|D]q\} } t| t rn|| |} n|t | |||} t| t r|| |} | j | d| qAt| t r|| |||} | j | d| qAyt| } WnBtk rO|t | |||} | j | d| YqAXx_| D]W} t| t r~|| |} n|t | |||} | j | d| qWWqAWdj | S)a^Encode 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 the function specified by quote_via (encoding and errors only if a component is a str). itemsrz1not a valid non-string sequence or mapping objectrr) hasattrrrsr1r-r3sysexc_infowith_tracebackrr2rr)rlZdoseqrr&r'Z quote_viaZtyZvatblkrr+ZeltrrrrsP      c Cs[t|trWy|jdj}Wn,tk rVtdt|dYnX|S)zto_bytes(u"URL") --> 'URL'.ASCIIzURL z contains non-ASCII characters)r1r2r%r) UnicodeErrorrepr)rbrrrto_bytesbs rcCst|j}|dddkrT|dddkrT|ddj}|dddkr|ddj}|S) z8unwrap('') --> 'type://host/path'.Nr0<>zURL:rr)r2strip)rbrrrunwrapos ,rcCsbtdkr!tjdtjatj|}|rX|j\}}|j|fSd|fS)z:splittype('type:opaquestring') --> 'type', 'opaquestring'.Nz ([^/:]+):(.*)) _typeprogrecompileDOTALLmatchgroupsrE)rbrridatarrr splittypexs rcCs|tdkr!tjdtjatj|}|rr|j\}}|rh|ddkrhd|}||fSd|fS)z;splithost('//host[:port]/path') --> 'host[:port]', '/path'.Nz//([^/#?]*)(.*)rro) _hostprogrrrrr)rbrZ host_portrrrr splithosts   rcCs.|jd\}}}|r$|nd|fS)zJsplituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.rLN)rO)hostuserrvrrr splitusersrcCs.|jd\}}}||r'|ndfS)z/splitpasswd('user:passwd') -> 'user', 'passwd'.rMN)rP)rrvZpasswdrrr splitpasswdsrcCsbtdkr!tjdtjatj|}|rX|j\}}|rX||fS|dfS)z*splitport('host:port') --> 'host', 'port'.Nz(.*):([0-9]*)$) _portprogrrrrr)rrrIrrr splitports  rr0c Csl|jd\}}}|s'|}n;|rbyt|}Wntk rWd}YnX||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.rMN)rOrHr)rZdefportrvrIZnportrrr splitnports    rcCs2|jd\}}}|r(||fS|dfS)z/splitquery('/path?query') --> '/path', 'query'.r{N)rO)rbrrvrlrrr splitquerys rcCs2|jd\}}}|r(||fS|dfS)z)splittag('/path#tag') --> '/path', 'tag'.r`N)rO)rbrrvtagrrrsplittags rcCs'|jd}|d|ddfS)zksplitattr('/path;attr1=value1;attr2=value2;...') -> '/path', ['attr1=value1', 'attr2=value2', ...].rfrr0N)r)rbZwordsrrr splitattrsrcCs.|jd\}}}||r'|ndfS)z-splitvalue('attr=value') --> 'attr', 'value'.rN)rP)attrrvrrrr splitvaluesrr)Sr<rr collections__all__rrrgZnon_hierarchicalZ uses_queryZ uses_fragmentrrrr Z_implicit_encodingZ_implicit_errorsr$r(r/r5objectr6r>r@rKrZr_Z_DefragResultBaseZ_SplitResultBaseZ_ParseResultBaseZ ResultBaserrrrrrrerrhrxrrrrrrrrrrrrr r r frozensetrrrr defaultdictrr r r rrrrrrrrrrrrrrrrrrrrs                   : E  "/  , O