Ρς
;0ϋIc           @   sv   d  Z  h  Z x< e d  D]. Z e e  e d e <e e  e d e <q Wd   Z d d d  Z d d d  Z d S(	   s   Parse (absolute and relative) URLs.

See RFC 1808: "Relative Uniform Resource Locators", by R. Fielding,
UC Irvine, June 1995.
i   s   %02xs   %02Xc      	   C   sΏ   |  i  d  } x  t d t |   D] } | | } y t | d  | d | | <Wq% t j
 o d | | | <q% t j
 o, t t | d  d   | d | | <q% Xq% Wd i |  S(   s"   unquote('abc%20def') -> 'abc def'.t   %i   i   i   t    (	   t   splitt   xranget   lent	   _hextochrt   KeyErrort   UnicodeDecodeErrort   unichrt   intt   join(   t   st   rest   it   item(    (    s;   /afs/cs.wisc.edu/u/s/b/sblanas/public/html/code/urlparse.pyt   unquote   s     
.i    c         C   s\   h  } xO t  |  | |  D]; \ } } | | j o | | i |  q | g | | <q W| S(   sͺ  Parse a query given as a string argument.

        Arguments:

        qs: URL-encoded query string to be parsed

        keep_blank_values: flag indicating whether blank values in
            URL 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.
    (   t	   parse_qslt   append(   t   qst   keep_blank_valuest   strict_parsingt   dictt   namet   value(    (    s;   /afs/cs.wisc.edu/u/s/b/sblanas/public/html/code/urlparse.pyt   parse_qs   s     c         C   s8  g  } |  i  d  D]# } | i  d  D] } | | q' q ~ } g  } xλ | D]γ } | o | o qM n | i  d d  }	 t |	  d j o: | o t d | f  n | o |	 i d  qΙ qM n t |	 d  p | oO t |	 d i d	 d
   }
 t |	 d i d	 d
   } | i |
 | f  qM qM W| S(   s  Parse a query given as a string argument.

    Arguments:

    qs: URL-encoded query string to be parsed

    keep_blank_values: flag indicating whether blank values in
        URL 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   &t   ;t   =i   i   s   bad query field: %rR   i    t   +t    (   R   R   t
   ValueErrorR   R   t   replace(   R   R   R   t   _[1]t   s1t   s2t   pairst   rt
   name_valuet   nvR   R   (    (    s;   /afs/cs.wisc.edu/u/s/b/sblanas/public/html/code/urlparse.pyR   3   s$    @ N(   t   __doc__R   t   rangeR   t   chrR   R   R   (    (    (    s;   /afs/cs.wisc.edu/u/s/b/sblanas/public/html/code/urlparse.pyt   <module>   s    	