ó xFWgc@sãdZddlZddddddd 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 Zd(Z d)Z d*Z iZ d+„Z d,„Zd-efd.„ƒYZdd/lmZd0ed0d1ƒefd2„ƒYZd3ed3d4ƒefd5„ƒYZded6„Zd7„Zd8d9„Zd:„Zded;„Zd<„Zd=„Zed>„Zd?„ZyeWne k r}d@„Z!n XdA„Z!dBZ"e#dC„e"DƒƒZ$ej%dDƒZ&dE„Z'd8d8ddF„Z)d8d8ddG„Z*dS(Hs2Parse (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. iÿÿÿÿNturlparset urlunparseturljoint urldefragturlsplitt urlunsplittparse_qst parse_qsltftpthttptgophertnntptimaptwaistfilethttpstshttptmmstprosperotrtsptrtsputtsftptsvnssvn+sshttelnettsnewstrsynctnfstgitsgit+sshthdltsiptsipstteltmailtotnewssAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.s!  icCstd„|DƒƒS(Ncss!|]}t|ƒdkVqdS(i€N(tord(t.0tchar((s/usr/lib/python2.7/urlparse.pys Ns(tall(tstring((s/usr/lib/python2.7/urlparse.pytis_asciiMscCstjƒdS(sClear the parse cache.N(t _parse_cachetclear(((s/usr/lib/python2.7/urlparse.pyt clear_cachePst ResultMixincBsJeZdZed„ƒZed„ƒZed„ƒZed„ƒZRS(s-Shared methods for the parsed result objects.cCsX|j}d|krT|jddƒd}d|krP|jddƒd}n|SdS(Nt@iit:(tnetloctrsplittsplittNone(tselfR/tuserinfo((s/usr/lib/python2.7/urlparse.pytusernameXs   cCsR|j}d|krN|jddƒd}d|krN|jddƒdSndS(NR-iiR.(R/R0R1R2(R3R/R4((s/usr/lib/python2.7/urlparse.pytpasswordbs    cCsŠ|jjdƒd}d|krId|krI|jdƒddjƒSd|krl|jdƒdjƒS|dkr|dS|jƒSdS( NR-iÿÿÿÿt[t]iiR.R(R/R1tlowerR2(R3R/((s/usr/lib/python2.7/urlparse.pythostnameks  cCs|jjdƒdjdƒd}d|kr}|jdƒd}|r}t|dƒ}d|kondknrz|Sq}ndS( NR-iÿÿÿÿR8R.ii iiÿÿ(R/R1tintR2(R3R/tport((s/usr/lib/python2.7/urlparse.pyR<ws#  (t__name__t __module__t__doc__tpropertyR5R6R:R<(((s/usr/lib/python2.7/urlparse.pyR,Us    (t namedtuplet SplitResults!scheme netloc path query fragmentcBseZdZd„ZRS(cCs t|ƒS(N(R(R3((s/usr/lib/python2.7/urlparse.pytgeturl‰s((R=R>t __slots__RC(((s/usr/lib/python2.7/urlparse.pyRB…st ParseResults(scheme netloc path params query fragmentcBseZdZd„ZRS(cCs t|ƒS(N(R(R3((s/usr/lib/python2.7/urlparse.pyRC‘s((R=R>RDRC(((s/usr/lib/python2.7/urlparse.pyREscCsst|||ƒ}|\}}}}}|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 _splitparamsRE(turltschemetallow_fragmentsttupleR/tquerytfragmenttparams((s/usr/lib/python2.7/urlparse.pyR•s cCsed|kr@|jd|jdƒƒ}|dkrO|dfSn|jdƒ}|| ||dfS(Nt/RFiRi(tfindtrfind(RIti((s/usr/lib/python2.7/urlparse.pyRH£s    icCsbt|ƒ}x>dD]6}|j||ƒ}|dkrt||ƒ}qqW|||!||fS(Ns/?#i(tlenRQtmin(RItstarttdelimtctwdelim((s/usr/lib/python2.7/urlparse.pyt _splitnetloc¬s    cCsÅ| st|tƒ rdSddl}|jddƒ}|jddƒ}|jddƒ}|jddƒ}|jd|ƒ}||kr‘dSx-dD]%}||kr˜td |ƒ‚q˜q˜WdS( Niÿÿÿÿu@uu:u#u?tNFKCs/?#@:s>netloc %r contains invalid characters under NFKC normalization(t isinstancetunicodet unicodedatatreplacet normalizet ValueError(R/R^tntnetloc2RX((s/usr/lib/python2.7/urlparse.pyt _checknetloc´s    c Cs=|jtƒ}|jtƒ}t|ƒ}|||t|ƒt|ƒf}tj|dƒ}|rg|Sttƒt krƒt ƒnd}}}|j dƒ}|dkrRt |dƒrR|dj ƒrR|| dkrå|| jƒ}||d}|d dkrat|dƒ\}}d|kr7d |ksOd |krad|kratd ƒ‚qan|rŽd |krŽ|jd dƒ\}}nd |krµ|jd dƒ\}}nt|ƒt|||||ƒ} | t|<| Sxj|| D]} | tkrðPqðqðW||d} | s5td „| DƒƒrR|| jƒ| }}qRn|d dkr¹t|dƒ\}}d|krd |ks§d |kr¹d|kr¹td ƒ‚q¹n|ræd |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//R7R8sInvalid IPv6 URLt#t?css|]}|dkVqdS(t 0123456789N((R$RX((s/usr/lib/python2.7/urlparse.pys òsN(tlstript_WHATWG_C0_CONTROL_OR_SPACEtstriptboolttypeR)tgetR2RTtMAX_CACHE_SIZER+RQR(tisalphaR9RZRaR1RdRBt scheme_charstany( RIRJRKtkeytcachedR/RMRNRStvRXtrest((s/usr/lib/python2.7/urlparse.pyRÇs^ ! ,       cCsJ|\}}}}}}|r1d||f}nt|||||fƒS(súPut 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(tdataRJR/RIRORMRN((s/usr/lib/python2.7/urlparse.pyRscCsÀ|\}}}}}|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//iRPRR.RfRe(t uses_netloc(RvRJR/RIRMRN((s/usr/lib/python2.7/urlparse.pyRs( cCsh|s |S|s|St|d|ƒ\}}}}}}t|||ƒ\} } } } } }| |kst| tkrx|S| tkr¯| r¦t| | | | | |fƒS|} n| d dkrÛt| | | | | |fƒS| r | r |} |} | s|} nt| | | | | |fƒS|jdƒd | jdƒ}|ddkr]d|dqss([-]+)cCsOt|ƒr¦d|kr|Stj|ƒ}|dg}|j}xUtdt|ƒdƒD];}|tt||ƒƒjdƒƒ|||dƒqZWdj |ƒS|jdƒ}t|ƒdkrË|S|dg}|j}x^|dD]R}y$|t |d ƒ||dƒWqìt k r=|dƒ||ƒqìXqìWdj |ƒS(s"unquote('abc%20def') -> 'abc def'.t%iiitlatin1R( RŒt_asciireR1tappendtrangeRTtunquotetstrtdecodeR{t _hextochrtKeyError(R…tbitstresR”RStitem((s/usr/lib/python2.7/urlparse.pyR–us.    #     cCs]i}xPt||||ƒD]9\}}||krH||j|ƒq|g|| sh      .""  =  4