zfc@s&dZddlZddlZddddddd d gZd d d ddddddddddddddgZd d d ddddddddddddddddddd d!gZd d"dd dddddd#d$dddd%gZd d"d&d'ddddd#d$g Zd dddddd ddd#d$dg Zd d"d d d'ddddddddg Z d(Z d)Z d*d+d,gZ d-Z iZd.Zd/efd0YZdd1lmZd2ed2d3efd4YZd5ed5d6efd7YZded8Zd9Zd:d;Zd<Zd=Zded>Zd?Zd@ZedAZdBZ ye!Wne"k rdCZ#n XdDZ#dEZ$e%dFe$DZ&ej'dGZ(dHZ)d:d:dddIZ+dJe,fdKYZ-dLZ.da/d:d:dddMZ0dS(Ns3Parse (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. Zwinski, 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. The WHATWG URL Parser spec should also be considered. We are not compliant with it either due to existing user code API behavior expectations (Hyrum's Law). It serves as a useful guide when making changes. iNturlparset urlunparseturljoint urldefragturlsplitt urlunsplittparse_qst parse_qsltftpthttptgophertnntptimaptwaistfilethttpstshttptmmstprosperotrtsptrtsputtsftptsvnssvn+sshttelnettsnewstrsynctnfstgitsgit+sshthdltsiptsipstteltmailtotnewssAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.s!  s s s icCstjdS(sClear the parse cache.N(t _parse_cachetclear(((s /usr/lib64/python2.7/urlparse.pyt clear_cachePst ResultMixincBsJeZdZedZedZedZedZRS(s-Shared methods for the parsed result objects.cCsX|j}d|krT|jddd}d|krP|jddd}n|SdS(Nt@iit:(tnetloctrsplittsplittNone(tselfR)tuserinfo((s /usr/lib64/python2.7/urlparse.pytusernameXs   cCsR|j}d|krN|jddd}d|krN|jdddSndS(NR'iiR((R)R*R+R,(R-R)R.((s /usr/lib64/python2.7/urlparse.pytpasswordbs    cCs|jjdd}d|krId|krI|jdddjSd|krl|jddjS|dkr|dS|jSdS( NR'it[t]iiR(R(R)R+tlowerR,(R-R)((s /usr/lib64/python2.7/urlparse.pythostnameks  cCs|jjddjdd}d|kr}|jdd}|r}t|d}d|kondknrz|Sq}ndS( NR'iR2R(ii ii(R)R+tintR,(R-R)tport((s /usr/lib64/python2.7/urlparse.pyR6ws#  (t__name__t __module__t__doc__tpropertyR/R0R4R6(((s /usr/lib64/python2.7/urlparse.pyR&Us    (t namedtuplet SplitResults!scheme netloc path query fragmentcBseZdZdZRS(cCs t|S(N(R(R-((s /usr/lib64/python2.7/urlparse.pytgeturls((R7R8t __slots__R=(((s /usr/lib64/python2.7/urlparse.pyR<st ParseResults(scheme netloc path params query fragmentcBseZdZdZRS(cCs t|S(N(R(R-((s /usr/lib64/python2.7/urlparse.pyR=s((R7R8R>R=(((s /usr/lib64/python2.7/urlparse.pyR?scCsst|||}|\}}}}}|tkrTd|krTt|\}}nd}t||||||S(s#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.t;R(Rt uses_paramst _splitparamsR?(turltschemetallow_fragmentsttupleR)tquerytfragmenttparams((s /usr/lib64/python2.7/urlparse.pyRs cCsed|kr@|jd|jd}|dkrO|dfSn|jd}|| ||dfS(Nt/R@iRi(tfindtrfind(RCti((s /usr/lib64/python2.7/urlparse.pyRBs    icCsbt|}x>dD]6}|j||}|dkrt||}qqW|||!||fS(Ns/?#i(tlenRKtmin(RCtstarttdelimtctwdelim((s /usr/lib64/python2.7/urlparse.pyt _splitnetlocs    cCs| st|t rdSddl}|jdd}|jdd}|jdd}|jdd}|jd|}||krdSx-dD]%}||krtd |qqWdS( Niu@uu:u#u?tNFKCs/?#@:s>netloc %r contains invalid characters under NFKC normalization(t isinstancetunicodet unicodedatatreplacet normalizet ValueError(R)RXtntnetloc2RR((s /usr/lib64/python2.7/urlparse.pyt _checknetlocs    cCs'x tD]}|j|d}qW|S(NR(t_UNSAFE_URL_BYTES_TO_REMOVERY(RCtb((s /usr/lib64/python2.7/urlparse.pyt_remove_unsafe_bytes_from_urls c Cs5t|}t|}|jt}|jt}t|}|||t|t|f}tj|d}|r|St tt krt nd}}}|j d}|dkrJ|| dkr|| j }||d}|d dkrYt|d\}}d|kr/d |ksGd |krYd|krYtd qYn|rd |kr|jd d\}}nd |kr|jd d\}}nt|t|||||} | t|<| Sxj|| D]} | tkrPqqW||d} | s-td | DrJ|| j | }}qJn|d dkrt|d\}}d|krd |ksd |krd|krtd qn|rd |kr|jd d\}}nd |kr|jd d\}}nt|t|||||} | t|<| S(sParse 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.RR(iR iis//R1R2sInvalid IPv6 URLt#t?css|]}|dkVqdS(t 0123456789N((t.0RR((s /usr/lib64/python2.7/urlparse.pys sN(Ratlstript_WHATWG_C0_CONTROL_OR_SPACEtstriptboolttypeR#tgetR,RNtMAX_CACHE_SIZER%RKR3RTR[R+R^R<t scheme_charstany( RCRDREtkeytcachedR)RGRHRMtvRRtrest((s /usr/lib64/python2.7/urlparse.pyRsb   !         cCsJ|\}}}}}}|r1d||f}nt|||||fS(sPut 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).s%s;%s(R(tdataRDR)RCRIRGRH((s /usr/lib64/python2.7/urlparse.pyR scCs|\}}}}}|s=|rw|tkrw|d dkrw|r`|d dkr`d|}nd|pld|}n|r|d|}n|r|d|}n|r|d|}n|S( skCombine 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).is//iRJRR(RcRb(t uses_netloc(RsRDR)RCRGRH((s /usr/lib64/python2.7/urlparse.pyRs( cCsh|s |S|s|St|d|\}}}}}}t|||\} } } } } }| |kst| tkrx|S| tkr| rt| | | | | |fS|} n| d dkrt| | | | | |fS| r | r |} |} | s|} nt| | | | | |fS|jdd | jd}|ddkr]d|dvss([-]+)cCsOt|rd|kr|Stj|}|dg}|j}xUtdt|dD];}|tt||jd|||dqZWdj |S|jd}t|dkr|S|dg}|j}x^|dD]R}y$|t |d ||dWqt k r=|d||qXqWdj |S(s"unquote('abc%20def') -> 'abc def'.t%iiitlatin1R( Rt_asciireR+tappendtrangeRNtunquotetstrtdecodeRxt _hextochrtKeyError(RtbitstresRRMtitem((s /usr/lib64/python2.7/urlparse.pyRzs.    #     cCs`i}xSt|||||D]9\}}||krK||j|q|g||Warning for using default `separator` in parse_qs or parse_qsl(R7R8R9(((s /usr/lib64/python2.7/urlparse.pyRss/etc/python/urllib.cfgcCsp| st|ttf r8|dk r8tdnt}|dkrt}d}|dkrtjj |}d}n|dkryt t }Wnt k rqX|Bddl } | j } | j|| j d|}|aWdQXt }n|dkrbd|krYddlm} | d d d d d ddtddnd}q|dkrw|}qt|dkrtdj||ddqn|dk r||krd|jd|jd} nd|j|} || krtdqn||krbg|jdD]"} | jdD] }|^qJq7}n"g|j|D] } | ^qr}g}x|D]}| r| rqn|jdd}t|dkr|rtd|fn|r|jdqqnt|ds|rt|djdd}t|djdd}|j||fqqW|S(sParse 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. max_num_fields: int. If set, then throws a ValueError if there are more than n fields read by parse_qsl(). Returns a list, as G-d intended. s*Separator must be of type string or bytes.tPYTHON_URLLIB_QS_SEPARATORsenvironment variableiNRR@(twarns0The default separator of urlparse.parse_qsl and s1parse_qs was changed to '&' to avoid a web cache s"poisoning issue (CVE-2021-23336). s4By default, semicolons no longer act as query field s separators. s3See https://access.redhat.com/articles/5860431 for s more details.t stacklevelit&tlegacyis{} (from {}) must contain s1 character, or "legacy". See s<https://access.redhat.com/articles/5860431 for more details.sMax number of fields exceededt=sbad query field: %rRit+t (RVRtbytesR,R[tobjectt_default_qs_separatortostenvironRktopent_QS_SEPARATOR_CONFIG_FILENAMEtEnvironmentErrort ConfigParsertreadfptwarningsRRRNtformattcountR+RRRY(RRRRRt_legacyt envvar_namet config_sourceRRtconfigRt num_fieldsts1ts2tpairstrt name_valuetnvRR((s /usr/lib64/python2.7/urlparse.pyRst)                #  #  ;" (1R9treRt__all__RvRtRAtnon_hierarchicalt uses_queryt uses_fragmentRmRgR_RlR#R%RR&t collectionsR;R<R?tTrueRRBRTR^RaRRRRRRWt NameErrorRRRRtcompileRRR,RtRuntimeWarningRRRR(((s /usr/lib64/python2.7/urlparse.pyt!sv      .""   =  4