U
    	Ú²g9  ã                   @   sŠ   d Z dZdZg ZdZdZddlZddd	d
ddddddddddddddddgZdd„ Z	dd„ Z
edkr†ddlZG d d!„ d!ejƒZe ¡  dS )"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                 C   sX   | }t | ƒ}tD ]B\}}||k r$ qT||kr||krd dd„ |  d¡D ƒ¡} qTq|S )NÚ c                 S   s   g | ]}d | ‘qS )z%%%2X© )Ú.0Úor   r   ú4/tmp/pip-unpacked-wheel-qyr_1luu/httplib2/iri2uri.pyÚ
<listcomp>7   s     zencode.<locals>.<listcomp>úutf-8)ÚordÚescape_rangeÚjoinÚencode)ÚcÚretvalÚiÚlowÚhighr   r   r   r   0   s    r   c                 C   s^   t | tƒrZtj | ¡\}}}}}| d¡ d¡}tj |||||f¡} d dd„ | D ƒ¡} | S )zžConvert 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   c                 S   s   g | ]}t |ƒ‘qS r   )r   )r   r   r   r   r   r	   G   s     ziri2uri.<locals>.<listcomp>)	Ú
isinstanceÚstrÚurllibÚparseÚurlsplitr   ÚdecodeÚ
urlunsplitr   )ÚuriÚschemeÚ	authorityÚpathÚqueryÚfragmentr   r   r   Úiri2uri<   s    
r"   Ú__main__c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestc                 C   s2   ddddddddg}|D ]}|   |t|ƒ¡ qd	S )
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"   )ÚselfZ	invariantr   r   r   r   Ú	test_urisO   s    ø
zTest.test_urisc                 C   s~   |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   d	td
ƒ¡ |   d	ttd
ƒƒ¡ |  d	td
 d¡ƒ¡ dS )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"   ZassertNotEqualr   )r&   r   r   r   Útest_iri^   s6    þþþþ
þÿþzTest.test_iriN)Ú__name__Ú
__module__Ú__qualname__r'   r(   r   r   r   r   r$   N   s   r$   )Ú__doc__Ú
__author__Ú__copyright__Z__contributors__Ú__version__Ú__license__Úurllib.parser   r   r   r"   r)   ZunittestZTestCaser$   Úmainr   r   r   r   Ú<module>   sB   ì.