tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
M\¬Qc@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
iZ d*„Z d+e fd,„ƒYZdd-lmZd.ed.d/ƒefd0„ƒYZd1ed1d2ƒefd3„ƒYZded4„Zd5„Zd6d7„Zded8„Zd9„Zd:„Zed;„Zd<„ZyeWnek
red=„Zn
Xd>„Zd?Ze d@„eDƒƒZ!ej"dAƒZ#dB„Z$d6d6dC„Z%d6d6dD„Z&dS(EscParse (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.
 
iÿÿÿÿNturlparset
urlunparseturljoint    urldefragturlsplitt
urlunsplittparse_qst    parse_qsltftpthttptgophertnntptimaptwaistfilethttpstshttptmmstprosperotrtsptrtsputtsftptsvnssvn+sshttelnettsnewstrsynctnfstgitsgit+sshthdltsiptsipstteltmailtotnewssAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.icCstjƒdS(sClear the parse cache.N(t _parse_cachetclear(((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyt clear_cacheDst 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((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pytusernameLs      cCsR|j}d|krN|jddƒd}d|krN|jddƒdSndS(NR'iiR((R)R*R+R,(R-R)R.((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pytpasswordVs       cCsŠ|jjdƒd}d|krId|krI|jdƒddjƒSd|krl|jdƒdjƒS|dkr|dS|jƒSdS(    NR'iÿÿÿÿt[t]iiR(R(R)R+tlowerR,(R-R)((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pythostname_s  cCsx|jjdƒdjdƒd}d|krt|jdƒd}t|dƒ}d|kohdknrt|SndS(    NR'iÿÿÿÿR2R(ii
iiÿÿ(R)R+tintR,(R-R)tport((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyR6ks# (t__name__t
__module__t__doc__tpropertyR/R0R4R6(((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyR&Is
 
     (t
namedtuplet SplitResults!scheme netloc path query fragmentcBseZdZd„ZRS(cCs
t|ƒS(N(R(R-((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pytgeturl|s((R7R8t    __slots__R=(((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyR<xst ParseResults(scheme netloc path params query fragmentcBseZdZd„ZRS(cCs
t|ƒS(N(R(R-((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyR=„s((R7R8R>R=(((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyR?€scCsst|||ƒ}|\}}}}}|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(Rt uses_paramst _splitparamsR?(turltschemetallow_fragmentsttupleR)tquerytfragmenttparams((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyRˆs cCsed|kr@|jd|jdƒƒ}|dkrO|dfSn|jdƒ}|| ||dfS(Nt/R@iRi(tfindtrfind(RCti((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyRB–s    icCsbt|ƒ}x>dD]6}|j||ƒ}|dkrt||ƒ}qqW|||!||fS(Ns/?#i(tlenRKtmin(RCtstarttdelimtctwdelim((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyt _splitnetlocŸs    c Csët|ƒ}|||t|ƒt|ƒf}tj|dƒ}|rI|Sttƒtkretƒnd}}}|jdƒ}|dkr
|| dkr|| j    ƒ}||d}|d dkr#t
|dƒ\}}d|krùd    |ksd    |kr#d|kr#t d
ƒ‚q#n|rPd |krP|j d dƒ\}}nd |krw|j d dƒ\}}nt |||||ƒ}    |    t|<|    Sxj|| D]}
|
tkr¨Pq¨q¨W||d} | sítd „| Dƒƒr
|| j    ƒ| }}q
n|d dkrqt
|dƒ\}}d|krGd    |ks_d    |krqd|krqt d
ƒ‚qqn|ržd |krž|j d dƒ\}}nd |krÅ|j d dƒ\}}nt |||||ƒ}    |    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//R1R2sInvalid IPv6 URLt#t?css|]}|dkVqdS(t
0123456789N((t.0RR((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pys    <genexpr>ÍsN(tboolttypeR#tgetR,RNtMAX_CACHE_SIZER%RKR3RTt
ValueErrorR+R<t scheme_charstany( RCRDREtkeytcachedR)RGRHRMtvRRtrest((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyR§sV !
 
 
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(tdataRDR)RCRIRGRH((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/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(RVRU(t uses_netloc(RdRDR)RCRGRH((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyRès( c
Csg|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|d<nxd|kr||jdƒq`Wxqd}t|ƒd}xU||krì||dkrß||dd    krß||d|d5Pn|d}q™WPq€|ddgkrd|d<n2t|ƒdkrB|ddkrBdg|d)nt|    |
dj|ƒ| | |fƒS(
saJoin a base URL and a possibly relative URL to form an absolute
    interpretation of the latter.RiRJiÿÿÿÿt.s..iiþÿÿÿ(Rs..(Rt uses_relativeReRR+tremoveRNtjoin(tbaseRCREtbschemetbnetloctbpathtbparamstbqueryt    bfragmentRDR)tpathRIRGRHtsegmentsRMtn((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyRúsX$$               "cCs`d|krRt|ƒ\}}}}}}t|||||dfƒ}||fS|dfSdS(s¿Removes 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.
    RURN(RR(RCtsRstptatqtfragtdefrag((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyR.s
 
cCsdS(Ni((tx((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyt _is_unicode?scCs t|tƒS(N(t
isinstancetunicode(Rz((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyR{Bst0123456789ABCDEFabcdefccs?|]5}tD](}||tt||dƒƒfVq qdS(iN(t_hexdigtchrR5(RXRvtb((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pys    <genexpr>Kss([-]+)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_asciireR+tappendtrangeRNtunquotetstrtdecodeRit    _hextochrtKeyError(RttbitstresR…RMtitem((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyR‡Os.       #       
cCsZi}xMt|||ƒD]9\}}||krE||j|ƒq|g||<qW|S(s²Parse 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.
    (RR…(tqstkeep_blank_valueststrict_parsingtdicttnametvalue((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyRks  c Cs$g|jdƒD]"}|jdƒD] }|^q#q}g}xß|D]×}| r_| r_qEn|jddƒ}t|ƒdkr¸|rœtd|f‚n|rE|jdƒq¸qEnt|dƒsÎ|rEt|djd    d
ƒƒ}    t|djd    d
ƒƒ}
|j|    |
fƒqEqEW|S( s¦Parse 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+RNR]R…R‡treplace( RRR‘ts1ts2tpairstrt
name_valuetnvR“R”((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyR…s"8 ('R9tret__all__RgReRAtnon_hierarchicalt
uses_queryt uses_fragmentR^R\R#R%tobjectR&t collectionsR;R<R?tTrueRRBRTRRRRRR}t    NameErrorR{RR’RŠtcompileR„R‡RR(((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/urlparse.pyt<module>sb        -""         7    
    4