ó
BÜXQc           @   s°   d  Z  d d l Z d d l Z e j d ƒ Z d „  Z d „  Z e j d ƒ j Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z e d k r¬ d d l Z e j ƒ  n  d S(   sC  RFC 3986 URI parsing and relative reference resolution / absolutization.

(aka splitting and joining)

Copyright 2006 John J. Lee <jjl@pobox.com>

This code is free software; you can redistribute it and/or modify it under
the terms of the BSD or ZPL 2.1 licenses (see the file COPYING.txt
included with the distribution).

iÿÿÿÿNs%   [^A-Za-z0-9\-_.~!*'();:@&=+$,/?%#[\]]c         C   sR   t  |  ƒ t  d ƒ k r- |  j | d ƒ }  n  |  j ƒ  }  t j |  j | ƒ d ƒ S(   Nt    t   replaces   !*'();:@&=+$,/?%#[]~(   t   typet   decodet   stript   urllibt   quotet   encode(   t   urlt   encoding(    (    s7   /scratch/rashmi/Condor_Script/src/mechanize/_rfc3986.pyt	   clean_url   s    c         C   s   t  t j |  ƒ ƒ S(   s  
    >>> is_clean_uri("ABC!")
    True
    >>> is_clean_uri(u"ABC!")
    True
    >>> is_clean_uri("ABC|")
    False
    >>> is_clean_uri(u"ABC|")
    False
    >>> is_clean_uri("http://example.com/0")
    True
    >>> is_clean_uri(u"http://example.com/0")
    True
    (   t   boolt   BAD_URI_CHARS_REt   search(   t   uri(    (    s7   /scratch/rashmi/Condor_Script/src/mechanize/_rfc3986.pyt   is_clean_uri-   s    s9   ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?c         C   sI   t  |  ƒ } | rE | j ƒ  } | d | d | d | d | d f Sd S(   s0   Return scheme, authority, path, query, fragment.i   i   i   i   i   N(   t   SPLIT_MATCHt   groups(   t   absolute_urit   matcht   g(    (    s7   /scratch/rashmi/Condor_Script/src/mechanize/_rfc3986.pyt   urlsplitC   s    c         C   sÇ   |  \ } } } } } g  } | j  } | d  k	 rG | | ƒ | d ƒ n  | d  k	 rj | d ƒ | | ƒ n  | | ƒ | d  k	 r— | d ƒ | | ƒ n  | d  k	 rº | d ƒ | | ƒ n  d j | ƒ S(   Nt   :s   //t   ?t   #R    (   t   appendt   Nonet   join(   t   partst   schemet	   authorityt   patht   queryt   fragmentt   rR   (    (    s7   /scratch/rashmi/Condor_Script/src/mechanize/_rfc3986.pyt
   urlunsplitJ   s"    	




c         C   s   t  t t |  ƒ t | ƒ ƒ ƒ S(   sZ   Join a base URI with a URI reference and return the resulting URI.

    See RFC 3986.
    (   R#   t   urljoin_partsR   (   t   base_urit   uri_reference(    (    s7   /scratch/rashmi/Condor_Script/src/mechanize/_rfc3986.pyt   urljoin]   s    c         C   s2  |  \ } } } } } | \ } } }	 }
 } | | k r? d  } n  | d  k	 rr | | t |	 ƒ |
 f \ } } } } n§ | d  k	 r› | t |	 ƒ |
 } } } nx |	 d k rË | } |
 d  k	 rÂ |
 } q| } nB |	 j d ƒ ré t |	 ƒ } n t | | |	 ƒ } t | ƒ } |
 } | } | } | } | | | | | f S(   NR    t   /(   R   t   remove_dot_segmentst
   startswitht   merge(   t
   base_partst   reference_partsR   R   R   R    R!   t   rschemet
   rauthorityt   rpatht   rqueryt	   rfragmentt   tschemet
   tauthorityt   tpatht   tqueryt	   tfragment(    (    s7   /scratch/rashmi/Condor_Script/src/mechanize/_rfc3986.pyR$   ‚   s,    	'		c         C   sš  g  } x„|  rŒ|  j  d ƒ r. |  d }  q	 n  |  j  d ƒ rM |  d }  q	 n  |  j  d ƒ rl |  d }  q	 n  |  d k r„ d }  q	 n  |  j  d ƒ r¶ |  d }  | r	 | j ƒ  q	 q	 n  |  d	 k rá d }  | r	 | j ƒ  q	 q	 n  |  d
 k rý |  d }  q	 n  |  d k r|  d }  q	 n  d } |  j  d ƒ r7d } n  |  j d | ƒ } | d k  r^d  } n  | j |  |  ƒ | d  k rPn  |  | }  q	 Wd j | ƒ S(   Ns   ../i   s   ./i   s   /./s   /.R(   s   /../s   /..t   .i   s   ..i    R    (   R*   t   popt   findR   R   R   (   R   R"   t   startt   ii(    (    s7   /scratch/rashmi/Condor_Script/src/mechanize/_rfc3986.pyR)   ·   sR    	





		c         C   sC   | d k r d | S| j  d ƒ } | d k r? | | d  | S| S(   NR    R(   i    i   (   t   rfind(   t   base_authorityt	   base_patht   ref_pathR<   (    (    s7   /scratch/rashmi/Condor_Script/src/mechanize/_rfc3986.pyR+   ç   s    t   __main__(   t   __doc__t   reR   t   compileR   R
   R   R   R   R   R#   R'   R$   R)   R+   t   __name__t   doctestt   testmod(    (    (    s7   /scratch/rashmi/Condor_Script/src/mechanize/_rfc3986.pyt   <module>   s   					%	5	0	