mò
­fIc           @   sÌ  d  Z  d d d d d d g Z d d d	 d
 d d d d d d d d d d g Z d d d	 d
 d d d d d d d d d d d d d d d g Z d	 d d d d d d d d g	 Z d d d d d d d d d d d d g Z d d d d d d d	 d d d d g Z d d d d	 d d
 d d d d d d d g Z d Z d Z	 h  a
 d  „  Z d d! d" „ Z d# „  Z d$ d% „ Z d d! d& „ Z d' „  Z d( „  Z d! d) „ Z d* „  Z d+ Z d, „  Z e d- j o e ƒ  n d. S(/   s   Parse (absolute and relative) URLs.

See RFC 1808: "Relative Uniform Resource Locators", by R. Fielding,
UC Irvine, June 1995.
t   urlparset
   urlunparset   urljoint	   urldefragt   urlsplitt
   urlunsplitt   ftpt   httpt   gophert   nntpt   imapt   waist   filet   httpst   shttpt   mmst   prosperot   rtspt   rtsput    t   telnett   snewst   rsynct   svns   svn+ssht   hdlt   mailtot   newst   sipsA   abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.i   c           C   s
   h  a  d S(   s   Clear the parse cache.N(   t   _parse_cache(    (    (    t%   /mit/python/lib/python2.4/urlparse.pyt   clear_cache&   s      i   c         C   ss   t  |  | | ƒ } | \ } } }  } } | t j o# d |  j o t	 |  ƒ \ }  } n d } | | |  | | | f 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   N(   R   t   urlt   schemet   allow_fragmentst   tuplet   netloct   queryt   fragmentt   uses_paramst   _splitparamst   params(   R    R!   R"   R#   R$   R&   R)   R%   (    (    R   R    ,   s     c         C   sl   d |  j o: |  i d |  i d ƒ ƒ } | d j  o |  d f SqV n |  i d ƒ } |  |  |  | d f S(   Nt   /R   i    R   i   (   R    t   findt   rfindt   i(   R    R-   (    (    R   R(   :   s    i    c         C   sV   x> d D]* } |  i | | ƒ } | d j o Pq q Wt |  ƒ } |  | | !|  | f S(   Ns   /?#i    (   t   cR    R+   t   startt   delimt   len(   R    R/   R.   R0   (    (    R   t   _splitnetlocC   s     	c         C   sh  |  | | f }	 t i |	 d
 ƒ } | o | Sn t t ƒ t	 j o t
 ƒ  n d } }
 } |  i d ƒ } | d j o#|  |  d j oÈ |  |  i ƒ  } |  | d }  |  d  d j o t |  d ƒ \ } }  n | o) d |  j o |  i d d ƒ \ }  } n d	 |  j o |  i d	 d ƒ \ }  }
 n | | |  |
 | f } | t |	 <| Sn xG |  |  D] } | t j o Pq\q\W|  |  i ƒ  |  | d } }  n | t j o* |  d  d j o t |  d ƒ \ } }  n | o6 | t j o) d |  j o |  i d d ƒ \ }  } n | t j o) d	 |  j o |  i d	 d ƒ \ }  }
 n | | |  |
 | f } | t |	 <| S(   s  Parse 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.R   t   :i    R   i   i   s   //t   #t   ?N(   R    R!   R"   t   keyR   t   gett   Nonet   cachedR1   t   MAX_CACHE_SIZER   R$   R%   R&   R+   R-   t   lowerR2   t   splitR#   R.   t   scheme_charst   uses_netloct   uses_fragmentt
   uses_query(   R    R!   R"   R-   R.   R$   R&   R9   R#   R6   R%   (    (    R   R   L   sH     
 	#!
c         C   sL   |  \ } } } } } } | o d | | f } n t | | | | | 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&   (    (    R   R   v   s    c         C   sÏ   |  \ } } } } } | p% | o] | t j oP | d  d j o? | o | d  d j o d | } n d | p d | } n | o | d | } n | o | d | } n | o | d | } n | S(	   Ni   s   //i   R*   R   R3   R5   R4   (   R!   R$   R    R%   R&   R>   (   RA   R!   R$   R    R%   R&   (    (    R   R      s   , c         C   sƒ  |  p | Sn | p |  Sn t |  d | ƒ \ }	 } } } } } t | |	 | ƒ \ }
 } } } } } |
 |	 j p |
 t j o | Sn |
 t j o1 | o  t |
 | | | | | f ƒ Sn | } n | d  d j o  t |
 | | | | | f ƒ Sn | p | p | p  t |
 | | | | | f ƒ Sn | i d ƒ d  | i d ƒ } | d d j o d | d <n x d | j o | i d ƒ qnWxx d } t | ƒ d } xZ | | j  oK | | d j o, | | d d
 j o | | d | d 5Pn | d } q©WPqW| d d g j o d | d <n6 t | ƒ d j o" | d d j o d g | d )n t |
 | d i | ƒ | | | f ƒ S(   sa   Join a base URL and a possibly relative URL to form an absolute
    interpretation of the latter.R   i   R*   iÿÿÿÿt   .s   ..i   iþÿÿÿN(   R   s   ..(   t   baseR    R    R"   t   bschemet   bnetloct   bpatht   bparamst   bqueryt	   bfragmentR!   R$   t   pathR)   R%   R&   t   uses_relativeR>   R   R<   t   segmentst   removeR-   R1   t   nt   join(   RC   R    R"   RG   RJ   R%   RE   RL   R)   RD   R!   R&   R$   R-   RN   RH   RF   RI   (    (    R   R   ‹   sN     $$ 
       &$c         C   se   d |  j oJ t |  ƒ \ } } } } } } t | | | | | d f ƒ } | | f Sn |  d f Sd S(   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.
    R4   R   N(
   R    R    t   sRN   t   pt   at   qt   fragR   t   defrag(   R    RR   RT   RU   RN   RS   RQ   RP   (    (    R   R   »   s     s™  
      http://a/b/c/d

      g:h        = <URL:g:h>
      http:g     = <URL:http://a/b/c/g>
      http:      = <URL:http://a/b/c/d>
      g          = <URL:http://a/b/c/g>
      ./g        = <URL:http://a/b/c/g>
      g/         = <URL:http://a/b/c/g/>
      /g         = <URL:http://a/g>
      //g        = <URL:http://g>
      ?y         = <URL:http://a/b/c/d?y>
      g?y        = <URL:http://a/b/c/g?y>
      g?y/./x    = <URL:http://a/b/c/g?y/./x>
      .          = <URL:http://a/b/c/>
      ./         = <URL:http://a/b/c/>
      ..         = <URL:http://a/b/>
      ../        = <URL:http://a/b/>
      ../g       = <URL:http://a/b/g>
      ../..      = <URL:http://a/>
      ../../g    = <URL:http://a/g>
      ../../../g = <URL:http://a/../g>
      ./../g     = <URL:http://a/b/g>
      ./g/.      = <URL:http://a/b/c/g/>
      /./g       = <URL:http://a/./g>
      g/./h      = <URL:http://a/b/c/g/h>
      g/../h     = <URL:http://a/b/c/h>
      http:g     = <URL:http://a/b/c/g>
      http:      = <URL:http://a/b/c/d>
      http:?y         = <URL:http://a/b/c/d?y>
      http:g?y        = <URL:http://a/b/c/g?y>
      http:g?y/./x    = <URL:http://a/b/c/g?y/./x>
c          C   sV  d  k  } d } | i d o7 | i d }
 |
 d j o | i }  ql t |
 ƒ }  n d  k } | i t ƒ }  xã |  i	 ƒ  }	 |	 p Pn |	 i ƒ  } | p qo n | d } t | ƒ } d | | f GHt | | ƒ } | p
 | } n d | } d | | f GHt | ƒ d j o; | d d	 j o* | | d
 j o d G| d
 Gd GHqMqo qo Wd  S(   NR   i   t   -i    s
   %-10s : %ss   <URL:%s>s
   %-10s = %si   t   =i   t   EXPECTEDs
   !!!!!!!!!!(   t   sysRC   t   argvt   fnt   stdint   fpt   opent   StringIOt
   test_inputt   readlinet   lineR<   t   wordsR    R    t   partsR   t   abst   wrappedR1   (   R]   Re   R_   R    Rd   RY   RC   Rc   Rf   Rb   R[   (    (    R   t   testì   s8    		   


$t   __main__N(   t   __doc__t   __all__RK   R>   t   non_hierarchicalR'   R@   R?   R=   R:   R   R   R    R(   R2   R   R   R   R   R   R`   Rg   t   __name__(   R'   R   R(   R   R   R   Rj   R   R@   Rg   RK   R   R2   R>   Rk   R:   R`   R    R?   R=   (    (    R   R5      s.   0?!*'-				*			0	"	