
|zJc           @   s  d  Z  e Z d d d d d d g Z d d l Z i* d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d  d! 6d" d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6d, d- 6d. d/ 6d0 d1 6d2 d3 6d4 d5 6d6 d7 6d6 d8 6d9 d: 6d; d< 6d= d> 6d? d@ 6dA dB 6dA dC 6dD dE 6dD dF 6dG dH 6dD dI 6d dJ 6dK dL 6dM dN 6dK dO 6dK dP 6dQ dR 6dK dS 6Z dT Z dU Z dV Z dW Z	 dX e e e	 f Z
 dY Z dZ Z d[ Z d\ e Z d] Z d^ e
 e e e e f Z d_ e
 e e e e f Z d` Z da Z db e e e e f Z dc e e e f Z e j e e j  Z e j e e j  Z dd   Z de   Z df   Z d e f dg     YZ d f  dh     YZ di i dj dk 6Z  e j e  e j e j! B Z" e j dl  Z# dm   Z$ d S(n   s/   Functions for working with generic syntax URIs.t   URIt   InvalidURIErrort   find_uris_in_textt   possible_uri_ret   merget   remove_dot_segmentsiNt   674t   acapt   80t   davt   2628t   dictt   53t   dnst   21t   ftpt   1096t   got   70t   gophert   1720t   h323t   httpt   443t   httpst   143t   imapt   631t   ippt   702s	   iris.beept   389t   ldapt   1038t   mtqpt   3905t   mupdatet   2049t   nfst   119t   nntpt   110t   popt   554t   rtspt   5060t   sipt   5061t   sipst   161t   snmpt   605s	   soap.beeps
   soap.beepst   23t   telnett   69t   tftpt   3372t   tipt   575t   vemmit   602s   xmlrpc.beeps   xmlrpc.beepst   210s   z39.50rs   z39.50st   1525t   prosperot   waiss   bzr+httpt   22s   bzr+ssht   6667t   irct   sftpt   ssht   3690t   svns   svn+sshs   (?P<scheme>[a-z][-a-z0-9+.]*)s9   (?P<userinfo>(?:[-a-z0-9._~!$&\'()*+,;=:]|%[0-9a-f]{2})*)ss   (?P<host>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|(?:[-a-z0-9._~!$&\'()*+,;=]|%[0-9a-f]{2})*|\[[0-9a-z:.]+\])s   (?P<port>[0-9]*)s!   (?P<authority>(?:%s@)?%s(?::%s)?)s2   (?:/(?:[-a-z0-9._~!$&\'()*+,;=:@]|%[0-9a-f]{2})*)*s]   (?:[-a-z0-9._~!$&\'()*+,;=@]|%[0-9a-f]{2})+(?:/(?:[-a-z0-9._~!$&\'()*+,;=:@]|%[0-9a-f]{2})*)*s^   (?:[-a-z0-9._~!$&\'()*+,;=:@]|%[0-9a-f]{2})+(?:/(?:[-a-z0-9._~!$&\'()*+,;=:@]|%[0-9a-f]{2})*)*s   /(?:%s)?t    s   (?P<hierpart>//%s%s|%s|%s|%s)s!   (?P<relativepart>//%s%s|%s|%s|%s)s=   (?P<query>(?:[-a-z0-9._~!$&\'()*+,;=:@/?\[\]]|%[0-9a-f]{2})*)s<   (?P<fragment>(?:[-a-z0-9._~!$&\'()*+,;=:@/?]|%[0-9a-f]{2})*)s   %s:%s(?:\?%s)?(?:#%s)?$s   %s(?:\?%s)?(?:#%s)?$c         C   s9   | r |  d k r d | S|  j  d  } |  | d  | S(   s/  Merge two URI path components into a single path component.

    Follows rules specified in Section 5.2.3 of RFC 3986.

    The algorithm in the RFC treats the empty basepath edge case
    differently for URIs with and without an authority section, which
    is why the third argument is necessary.
    RG   t   /i   (   t   rfind(   t   basepatht   relpatht   has_authorityt   slash(    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyR      s    	c         C   sJ  g  } x4|  r<|  j  d  r+ |  d }  q	 |  j  d  rG |  d }  q	 |  j  d  sb |  d k rs d |  d }  q	 |  j  d  s |  d	 k r d |  d
 }  t |  d k r9| d =q9q	 |  d k r d }  q	 |  j  d  r |  j d d  } n |  j d  } | d k  rt |   } n  | j |  |   |  | }  q	 Wd j |  S(   sq   Remove '.' and '..' segments from a URI path.

    Follows the rules specified in Section 5.2.4 of RFC 3986.
    s   ../i   s   ./i   s   /./s   /.RH   s   /../s   /..i   i    it   .s   ..RG   i   (   RN   s   ..(   t
   startswitht   lent   findt   appendt   join(   t   patht   outputRM   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyR      s,    		c         C   s   |  j  d  } d } x t |  D] \ } } | d k r@ q" n  y t | d  d  } Wn t k
 rm q" n Xt |  | k r t |  | d | | <q" d | | d f | | <q" Wd j |  S(   s   Return a version of 's' where no unreserved characters are encoded.

    Unreserved characters are defined in Section 2.3 of RFC 3986.

    Percent encoded sequences are normalised to upper case.
    t   %sB   ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~i    i   i   s   %%%02X%sRG   (   t   splitt	   enumeratet   intt
   ValueErrort   chrRS   (   t   stringt   resultt
   unreservedt   indext   itemt   ch(    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   normalise_unreserved   s    c           B   s   e  Z d  Z RS(   s   Invalid URI(   t   __name__t
   __module__t   __doc__(    (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyR      s   c        	   B   s   e  Z d  Z d d d d d d d d d  Z d   Z e d    Z e d    Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z RS(   s   A class that represents a URI.

    This class can represent arbitrary URIs that conform to the
    generic syntax described in RFC 3986.
    c	         C   s  | d k	 r` | d k r` | d k r` | d k r` | d k r` | d k r` | d k r` | d k su | d k su t d  | d k	 rt | t  r y | j d  } Wq t k
 r t d   q Xn  t j |  }	 |	 d k r t d |   n  |	 j	 d  |  _
 |	 j	 d  |  _ |	 j	 d  |  _ |	 j	 d  |  _ |	 j	 d	  }
 |	 j	 d
  } | d k rr|
 |  _ n |
 d t |  |  _ |	 j	 d  |  _ |	 j	 d  |  _ n | d k rt d   n  | d k r| d k	 s| d k	 rt d   n  | d k rt d   n  | |  _
 | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |  j   |  j
 d  k r|  j rt d |  j
   n  d S(!   s   Create a URI instance.

        Can be called with either a string URI or the component parts
        of the URI as keyword arguments.

        In either case, all arguments are expected to be appropriately
        URI encoded.
        se   URI() must be called with a single string argument or with URI components given as keyword arguments.t   ASCIIs%   URIs must consist of ASCII characterss   "%s" is not a valid URIt   schemet   userinfot   hostt   portt   hierpartt	   authorityi   t   queryt   fragments   URIs must have a schemes*   host must be given if userinfo or port ares   URIs must have a pathR   R   R   R   R4   R   t   mmsR+   RF   s   svn+ssht   bzrs   bzr+https   bzr+sshs   %s URIs must have a host nameN(   R   R   R   R   R4   R   Ro   R+   RF   s   svn+sshRp   s   bzr+https   bzr+ssh(   t   Nonet   AssertionErrort
   isinstancet   unicodet   encodet   UnicodeEncodeErrorR   t   uri_patt   matcht   groupRg   Rh   Ri   Rj   RT   RP   Rm   Rn   t
   _normalise(   t   selft   uriRg   Rh   Ri   Rj   RT   Rm   Rn   Rx   Rk   Rl   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   __init__   s\    
$$'$							
 	
c         C   sB  |  j  j   |  _  |  j d k	 r6 t |  j  |  _ n  |  j d k	 r` t |  j j    |  _ n  |  j d k r{ d |  _ n9 |  j d k	 r |  j t j |  j   k r d |  _ q n  |  j d k	 r |  j	 d k r d |  _	 n  t t
 |  j	   |  _	 |  j d k	 rt |  j  |  _ n  |  j d k	 r>t |  j  |  _ n  d S(   s(   Perform normalisation of URI components.RG   RH   N(   Rg   t   lowerRh   Rq   Rb   Ri   Rj   t   _default_portt   getRT   R   Rm   Rn   (   R{   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyRz     s"    c         C   sj   |  j  d k r d S|  j  } |  j d k	 rA d |  j | f } n  |  j d k	 rf d | |  j f } n  | S(   s   The authority part of the URIs   %s@%ss   %s:%sN(   Ri   Rq   Rh   Rj   (   R{   Rl   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyRl   /  s    	c         C   s1   |  j  } | d k r |  j Sd | |  j f Sd S(   s    The hierarchical part of the URIs   //%s%sN(   Rl   Rq   RT   (   R{   Rl   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt	   hier_part;  s    	c         C   s`   d |  j  |  j f } |  j d  k	 r9 | d |  j 7} n  |  j d  k	 r\ | d |  j 7} n  | S(   Ns   %s:%ss   ?%ss   #%s(   Rg   R   Rm   Rq   Rn   (   R{   R|   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   __str__D  s    c         C   s   d |  j  j t |   f S(   Ns   %s(%r)(   t	   __class__Rc   t   str(   R{   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   __repr__L  s    c         C   sr   t  | |  j  rj |  j | j k oi |  j | j k oi |  j | j k oi |  j | j k oi |  j | j k St Sd  S(   N(   Rs   R   Rg   Rl   RT   Rm   Rn   t   NotImplemented(   R{   t   other(    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   __eq__O  s    c         C   s(   |  j  |  } | t k r t S| Sd  S(   N(   R   R   (   R{   R   t   equal(    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   __ne__Y  s    c         K   sl   | s
 |  St  d |  j d |  j d |  j d |  j d |  j d |  j d |  j  } | j |  |  j	 |   S(   s;   Replace one or more parts of the URI, returning the result.Rg   Rh   Ri   Rj   RT   Rm   Rn   (
   R   Rg   Rh   Ri   Rj   RT   Rm   Rn   t   updateR   (   R{   t   partst	   baseparts(    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   replace`  s    						c         C   s  y |  j  |  SWn t k
 r$ n Xt j |  } | d k rO t d   n  t d |  j  } | j d  } | d k	 r | j d  | d <| j d  | d <| j d  | d <t | j d  d t	 |   | d	 <| j d
  | d
 <n | j d  } | j d
  } | d k rR|  j
 | d	 <| d k	 rB| | d
 <q|  j | d
 <ne | j d  rtt |  | d	 <n9 t |  j
 | d |  j d k	 | d	 <t | d	  | d	 <| | d
 <|  j | d <|  j | d <|  j | d <| j d  | d <|  j  |   S(   s   Resolve the given URI reference relative to this URI.

        Uses the rules from Section 5.2 of RFC 3986 to resolve the new
        URI.
        s   Invalid relative referenceRg   Rl   Rh   Ri   Rj   t   relativeparti   RT   Rm   RG   RH   RL   Rn   N(   R   R   t   relative_ref_patRx   Rq   R   Rg   Ry   R   RP   RT   Rm   RO   R   Ri   Rh   Rj   (   R{   t	   referenceRx   R   Rl   RT   Rm   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   resolveo  sD    $
c         C   s)   | j  d  s t  |  j   j |  S(   s   Append the given path to this URI.

        The path must not start with a slash, but a slash is added to
        base URI (before appending the path), in case it doesn't end
        with a slash.
        RH   (   RO   Rr   t   ensureSlashR   (   R{   RT   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyRR     s    c         C   s   |  j  | j  k s$ |  j | j k r( t S|  j | j k r> t S|  j } | j d  sc | d 7} n  | j } | j d  s | d 7} n  | j |  S(   s9   Returns True if the URI 'other' is contained by this one.RH   (   Rg   Rl   t   FalseRT   t   Truet   endswithRO   (   R{   R   RJ   t	   otherpath(    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   contains  s    		c         C   sL   t  |  d k r t S|  j j d  } | j d  } | t  |  | k S(   s@   Return True if the given domain name a parent of the URL's host.i    RN   (   RP   R   Ri   RW   (   R{   t   domaint   our_segmentst   domain_segments(    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   underDomain  s
    c         C   s1   |  j  j d  r |  S|  j d |  j  d  Sd S(   s:   Return a URI with the path normalised to end with a slash.RH   RT   N(   RT   R   R   (   R{   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyR     s    c         C   s6   |  j  j d  r. |  j d |  j  j d   S|  Sd S(   s>   Return a URI with the path normalised to not end with a slash.RH   RT   N(   RT   R   R   t   rstrip(   R{   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   ensureNoSlash  s    N(   Rc   Rd   Re   Rq   R}   Rz   t   propertyRl   R   R   R   R   R   R   R   RR   R   R   R   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyR       s"   @					
			2	
			s  
\b
(?:about|gopher|http|https|sftp|news|ftp|mailto|file|irc|jabber|xmpp)
:
(?:
  (?:
    # "//" authority path-abempty
    //
    (?: # userinfo
      [%(unreserved)s:]*
      @
    )?
    (?: # host
      \d+\.\d+\.\d+\.\d+ |
      [%(unreserved)s]*
    )
    (?: # port
      : \d*
    )?
    (?: / [%(unreserved)s:@]* )*
  ) | (?:
    # path-absolute
    /
    (?: [%(unreserved)s:@]+
        (?: / [%(unreserved)s:@]* )* )?
  ) | (?:
    # path-rootless
    [%(unreserved)s@]
    [%(unreserved)s:@]*
    (?: / [%(unreserved)s:@]* )*
  )
)
(?: # query
  \?
  [%(unreserved)s:@/\?\[\]]*
)?
(?: # fragment
  \#
  [%(unreserved)s:@/\?]*
)?
s   -a-zA-Z0-9._~%!$&'()*+,;=R^   s   ([,.?:);>]+)$c         c   sh   xa t  j |   D]P } | j   } t j d |  } y t |  } Wn t k
 rZ q n X| Vq Wd S(   s8   Scan a block of text for URIs, and yield the ones found.RG   N(   t   possible_uri_patt   finditerRy   t   uri_trailers_patt   subR    R   (   t   textRx   t
   uri_stringR|   (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyR   9  s    (%   Re   t   typet   __metaclass__t   __all__t   reR   t	   scheme_ret   userinfo_ret   host_ret   port_ret   authority_ret   path_abempty_ret   path_noscheme_ret   path_rootless_ret   path_absolute_ret   path_empty_ret   hier_part_ret   relative_part_ret   query_ret   fragment_ret   uri_ret   relative_ref_ret   compilet
   IGNORECASERw   R   R   R   Rb   t	   ExceptionR   R    R   t   VERBOSER   R   R   (    (    (    s1   /usr/lib/python2.7/dist-packages/lazr/uri/_uri.pyt   <module>   s   	



			 d