Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/
Upload File :
Current File : //usr/lib/python2.7/urlparse.pyc


|_c@sdZddddddddgZd	d
ddd
ddddddddddddgZd	d
dddd
dddddddddddddddddgZdd d!d"ddd
dd#d$g
Zd	d dd
d
ddddd#d$dddgZd
dd
ddddddd#d$dgZd	d d
dd"ddddddddg
Zd%Zd&Z	iZ
d'Zd(efd)YZ
d*d+lmZd,ed,d-e
fd.YZd/ed/d0e
fd1YZded2Zd3Zd4d5Zd6Zded7Zd8Zd9Zed:Zd;Zd<Zed=eDZd>Zd4d4d?Z d4d4d@Z!dAS(BscParse (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.

turlparset
urlunparseturljoint	urldefragturlsplitt
urlunsplittparse_qst	parse_qsltftpthttptgophertnntptimaptwaistfilethttpstshttptmmstprosperotrtsptrtsputtsftptsvnssvn+sshttelnettsnewstrsynctnfstgitsgit+sshthdltmailtotnewstsiptsipssAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.icCstjdS(sClear the parse cache.N(t_parse_cachetclear(((s/usr/lib/python2.7/urlparse.pytclear_cache?stResultMixincBsJeZdZedZedZedZedZRS(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/lib/python2.7/urlparse.pytusernameGs	cCsR|j}d|krN|jddd}d|krN|jdddSndS(NR&iiR'(R(R)R*R+(R,R(R-((s/usr/lib/python2.7/urlparse.pytpasswordQs	cCs|jjdd}d|krId|krI|jdddjSd|krl|jddjS|dkr|dS|jSdS(	NR&it[t]iiR'R(R(R*tlowerR+(R,R(((s/usr/lib/python2.7/urlparse.pythostnameZscCsW|jjddjdd}d|krO|jdd}t|dSdSdS(NR&iR1R'ii
(R(R*tintR+(R,R(tport((s/usr/lib/python2.7/urlparse.pyR5fs
#
(t__name__t
__module__t__doc__tpropertyR.R/R3R5(((s/usr/lib/python2.7/urlparse.pyR%Ds

	i(t
namedtupletSplitResults!scheme netloc path query fragmentcBseZdZdZRS(cCs
t|S(N(R(R,((s/usr/lib/python2.7/urlparse.pytgeturlus((R6R7t	__slots__R<(((s/usr/lib/python2.7/urlparse.pyR;qstParseResults(scheme netloc path params query fragmentcBseZdZdZRS(cCs
t|S(N(R(R,((s/usr/lib/python2.7/urlparse.pyR<}s((R6R7R=R<(((s/usr/lib/python2.7/urlparse.pyR>yscCsst|||}|\}}}}}|tkrTd|krTt|\}}nd}t||||||S(s#Parse a URL into 6 components:
    <scheme>://<netloc>/<path>;<params>?<query>#<fragment>
    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(Rtuses_paramst_splitparamsR>(turltschemetallow_fragmentsttupleR(tquerytfragmenttparams((s/usr/lib/python2.7/urlparse.pyRscCsed|kr@|jd|jd}|dkrO|dfSn|jd}|| ||dfS(Nt/R?iRi(tfindtrfind(RBti((s/usr/lib/python2.7/urlparse.pyRAs
icCsbt|}x>dD]6}|j||}|dkrt||}qqW|||!||fS(Ns/?#i(tlenRJtmin(RBtstarttdelimtctwdelim((s/usr/lib/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
isinstancetunicodetunicodedatatreplacet	normalizet
ValueError(R(RWtntnetloc2RQ((s/usr/lib/python2.7/urlparse.pyt_checknetlocs
cCst|}|||t|t|f}tj|d
}|rI|Stttkretnd}}}|jd}|dkr|| dkr|| j	}||d}|d dkr#t
|d\}}d|krd	|ksd	|kr#d|kr#td
q#n|rPd|krP|jdd\}}nd|krw|jdd\}}nt
|t|||||}	|	t|<|	Sxp|| D]}
|
tkrPqqWyt||d}Wqtk
r|| j	||d}}qXn|d dkrt
|d\}}d|krWd	|ksod	|krd|krtd
qn|r|tkrd|kr|jdd\}}n|tkrd|kr|jdd\}}nt
|t|||||}	|	t|<|	S(sParse a URL into 5 components:
    <scheme>://<netloc>/<path>?<query>#<fragment>
    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//R0R1sInvalid IPv6 URLt#t?N(tboolttypeR"tgetR+RMtMAX_CACHE_SIZER$RJR2RSRZR*R]R;tscheme_charsR4t
uses_fragmentt
uses_query(RBRCRDtkeytcachedR(RFRGRLtvRQt_testportnum((s/usr/lib/python2.7/urlparse.pyRs\!



&

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(tdataRCR(RBRHRFRG((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//iRIRR'R_R^(tuses_netloc(RkRCR(RBRFRG((s/usr/lib/python2.7/urlparse.pyRs(
c
Csg|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|d<nxd|kr||jdq`Wxqd}t|d}xU||kr||dkr||dd	kr||d|d5Pn|d}qWPq|ddgkrd|d<n2t|dkrB|ddkrBdg|d)nt|	|
dj|||
|fS(
saJoin a base URL and a possibly relative URL to form an absolute
    interpretation of the latter.RiRIit.s..ii(Rs..(Rt
uses_relativeRlRR*tremoveRMtjoin(tbaseRBRDtbschemetbnetloctbpathtbparamstbqueryt	bfragmentRCR(tpathRHRFRGtsegmentsRLR[((s/usr/lib/python2.7/urlparse.pyRsX$$		 

"cCs`d|krRt|\}}}}}}t|||||df}||fS|dfSdS(sRemoves 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.
    R^RN(RR(RBtsR[tptatqtfragtdefrag((s/usr/lib/python2.7/urlparse.pyR<s

t0123456789ABCDEFabcdefccs?|]5}tD](}||tt||dfVq
qdS(iN(t_hexdigtchrR4(t.0R|tb((s/usr/lib/python2.7/urlparse.pys	<genexpr>PscCs|jd}t|dkr%|S|d}x|dD]{}y|t|d |d7}Wq:tk
r|d|7}q:tk
r|tt|d d|d7}q:Xq:W|S(s"unquote('abc%20def') -> 'abc def'.t%iiii(R*RMt	_hextochrtKeyErrortUnicodeDecodeErrortunichrR4(Rztrestitem((s/usr/lib/python2.7/urlparse.pytunquoteSs


-cCsZi}xMt|||D]9\}}||krE||j|q|g||<qW|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.
    (Rtappend(tqstkeep_blank_valueststrict_parsingtdicttnametvalue((s/usr/lib/python2.7/urlparse.pyRcscCs$g|jdD]"}|jdD]}|^q#q}g}x|D]}|r_|r_qEn|jdd}t|dkr|rtd|fn|rE|jdqqEnt|ds|rEt|djd	d
}	t|djd	d
}
|j|	|
fqEqEW|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.

    Returns a list, as G-d intended.
    t&R?t=iisbad query field: %rRit+t (R*RMRZRRRX(RRRts1ts2tpairstrt
name_valuetnvRR((s/usr/lib/python2.7/urlparse.pyR}s"8
N("R8t__all__RnRltnon_hierarchicalR@RfReRdRcR"R$tobjectR%tcollectionsR:R;R>tTrueRRARSR]RRRRRRRRRRR(((s/usr/lib/python2.7/urlparse.pyt<module>sV	+""			9	
	4