
    Zճc9                         d Z dZdZg ZdZdZddlZg dZd Z	d	 Z
ed
k(  r+ddlZ G d dej                        Z ej                          yy)zConverts an IRI to a URI.z!Joe Gregorio (joe@bitworking.org)zCopyright 2006, Joe Gregorioz1.0.0MIT    N))   i  )i   i  )i   i  )i  i  )i   i )i   i )i   i )i   i )i   i )i   i )i   i )i   i )i  	 i	 )i  
 i
 )i   i )i   i )i   i )i  i )i   i )i   i c                     | }t        |       }t        D ]L  \  }}||k  r |S ||k\  s||k  sdj                  | j                  d      D cg c]  }d|z  	 c}      } |S  |S c c}w )N utf-8z%%%2X)ordescape_rangejoinencode)cretvalilowhighos         2/usr/lib/python3/dist-packages/httplib2/iri2uri.pyr   r   0   s~    FAA! 	Ts7 M 8T	WW188G3DEagkEFFM M Fs   A%
c                 R   t        | t              rt        j                  j	                  |       \  }}}}}|j                  d      j                  d      }t        j                  j                  |||||f      } dj                  | D cg c]  }t        |       c}      } | S c c}w )zConvert an IRI to a URI. Note that IRIs must be
    passed in a unicode strings. That is, do not utf-8 encode
    the IRI before passing it into the function.idnar   r   )	
isinstancestrurllibparseurlsplitr   decode
urlunsplitr
   )urischeme	authoritypathqueryfragmentr   s          r   iri2urir"   <   s     #s5;\\5J5J35O2D%$$V,33G<	 ll%%vy$x&PQgg#.Qvay./J /s   	B$__main__c                       e Zd Zd Zd Zy)Testc                 P    g d}|D ]  }| j                  |t        |              y)z6Test that URIs are invariant under the transformation.)z"ftp://ftp.is.co.za/rfc/rfc1808.txtz#http://www.ietf.org/rfc/rfc2396.txtz)ldap://[2001:db8::7]/c=GB?objectClass?onezmailto:John.Doe@example.comz&news:comp.infosystems.www.servers.unixztel:+1-816-555-1212ztelnet://192.0.2.16:80/z3urn:oasis:names:specification:docbook:dtd:xml:4.1.2N)assertEqualr"   )self	invariantr   s      r   	test_uriszTest.test_urisO   s.    	I ! 4  gcl34    c                    | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  d	t        d
             | j                  d	t        t        d
                   | j                  d	t        d
j                  d                   y)zFTest that the right type of escaping is done for each part of the URI.zhttp://xn--o3h.com/%E2%98%84u   http://☄.com/☄z%http://bitworking.org/?fred=%E2%98%84u   http://bitworking.org/?fred=☄z http://bitworking.org/#%E2%98%84u   http://bitworking.org/#☄z
#%E2%98%84u   #☄z/fred?bar=%E2%98%9A#%E2%98%84u   /fred?bar=☚#☄r   N)r'   r"   assertNotEqualr   )r(   s    r   test_irizTest.test_iri^   s    .89 7?@ 2:; \7<+@A/KL / STU /GNNwWr+   N)__name__
__module____qualname__r*   r.    r+   r   r%   r%   N   s    	4	r+   r%   )__doc__
__author____copyright____contributors____version____license__urllib.parser   r	   r   r"   r/   unittestTestCaser%   mainr2   r+   r   <module>r=      si    0
.  0	 z,x   ,\ HMMOc r+   