mò %U²Ic@sÌdZddddddgZddd d d d d dddddddgZddd d dd d d dddddddddddgZd ddddd d ddg Zddddd dddddddg Zdd d dddd ddddg Zdddd dd d dddd ddg ZdZdZ ha d „Z dd!d"„Z d#„Z d$d%„Zdd!d&„Zd'„Zd(„Zd!d)„Zd*„Zd+Zd,„Zed-jo eƒnd.S(/sParse (absolute and relative) URLs. See RFC 1808: "Relative Uniform Resource Locators", by R. Fielding, UC Irvine, June 1995. turlparset urlunparseturljoint urldefragturlsplitt urlunsplittftpthttptgophertnntptimaptwaistfilethttpstshttptmmstprosperotrtsptrtsputttelnettsnewstrsynctsvnssvn+sshthdltmailtotnewstsipsAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.icCs hadS(sClear the parse cache.N(t _parse_cache(((t%/data/zmath/lib/python2.4/urlparse.pyt clear_cache&sicCsst|||ƒ}|\}}}}}|tjo#d|jot |ƒ\}}nd}||||||fS(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;RN( Rturltschemetallow_fragmentsttupletnetloctquerytfragmentt uses_paramst _splitparamstparams(R R!R"R#R$R&R)R%((RR,scCsld|jo:|id|idƒƒ}|djo|dfSqVn|idƒ}|| ||dfS(Nt/RiRi(R tfindtrfindti(R R-((RR(:s   icCsVx>dD]*}|i||ƒ}|djoPqqWt|ƒ}|||!||fS(Ns/?#i(tcR R+tstarttdelimtlen(R R/R.R0((Rt _splitnetlocCs   c Csh|||f} ti| d ƒ}|o|Snttƒt jo t ƒnd}} }|idƒ}|djo#|| djoÈ|| iƒ}||d}|d djot|dƒ\}}n|o)d|jo|iddƒ\}}nd |jo|id dƒ\}} n|||| |f}|t| <|SnxG|| D]}|tjoPq\q\W|| iƒ||d}}n|tjo*|d djot|dƒ\}}n|o6|tjo)d|jo|iddƒ\}}n|tjo)d |jo|id dƒ\}} n|||| |f}|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.Rt:iRiis//t#t?N(R R!R"tkeyRtgettNonetcachedR1tMAX_CACHE_SIZERR$R%R&R+R-tlowerR2tsplitR#R.t scheme_charst uses_netloct uses_fragmentt uses_query( R R!R"R-R.R$R&R9R#R6R%((RRLsH       #! cCsL|\}}}}}}|od||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;%sN(R!R$R R)R%R&R(t.0R!R$R R)R%R&((RRvscCsÏ|\}}}}}|p%|o]|tjoP|d djo?|o|d djod|}nd|pd|}n|o|d|}n|o|d|}n|o|d|}n|S( Nis//iR*RR3R5R4(R!R$R R%R&R>(RAR!R$R R%R&((RRs,cCsƒ|p|Sn|p|Snt|d|ƒ\} }}}}}t|| |ƒ\} } }}}} | | jp | tjo|Sn| tjo1| o t| | |||| fƒSn|} n|d djo t| | |||| fƒSn|p |p|p t| | |||| fƒSn|idƒd |idƒ}|ddjod|dRR<tsegmentstremoveR-R1tntjoin(RCR R"RGRJR%RERLR)RDR!R&R$R-RNRHRFRI((RR‹sN$$        &$cCsed|joJt|ƒ\}}}}}}t|||||dfƒ}||fSn |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. R4RN( R RtsRNtptatqtfragRtdefrag(R RRRTRURNRSRQRP((RR»s  s™ http://a/b/c/d g:h = http:g = http: = g = ./g = g/ = /g = //g = ?y = g?y = g?y/./x = . = ./ = .. = ../ = ../g = ../.. = ../../g = ../../../g = ./../g = ./g/. = /./g = g/./h = g/../h = http:g = http: = http:?y = http:g?y = http:g?y/./x = c CsVdk}d}|ido7|id} | djo |i}qlt| ƒ}ndk}|itƒ}xã|i ƒ} | pPn| i ƒ}|pqon|d}t|ƒ}d||fGHt||ƒ}|p |}nd|}d||fGHt|ƒdjo;|dd jo*||d jod G|d Gd GHqMqoqoWdS( NRit-is %-10s : %sss %-10s = %sit=itEXPECTEDs !!!!!!!!!!(tsysRCtargvtfntstdintfptopentStringIOt test_inputtreadlinetlineR<twordsR RtpartsRtabstwrappedR1( R]ReR_R RdRYRCRcRfRbR[((Rttestìs8           $t__main__N(t__doc__t__all__RKR>tnon_hierarchicalR'R@R?R=R:RRRR(R2RRRRRR`Rgt__name__(R'RR(RRRRjRR@RgRKRR2R>RkR:R`RR?R=((RR5s.0?!*'-  * 0 "