3
…E	Vf  ã               @   sŽ   d Z dZdZg ZdZdZdZddlZd7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJgZ	d0d1„ Z
d2d3„ Zed4krŠddlZG d5d6„ d6ejƒZejƒ  dS )Kz%
iri2uri

Converts an IRI to a URI.

z!Joe Gregorio (joe@bitworking.org)zCopyright 2006, Joe Gregorioz1.0.0ZMITÚ
é    Né    éÿ×  é à  éÿø  é ù  éÏý  éðý  éïÿ  é   éýÿ é   éýÿ é   éýÿ é   éýÿ é   éýÿ é   éýÿ é   éýÿ é   éýÿ é  	 éýÿ	 é  
 éýÿ
 é   éýÿ é   éýÿ é   éýÿ é  éýÿ é   éýÿ é   éýÿ c             C   sX   | }t | ƒ}xFtD ]>\}}||k r$P ||kr||krdjdd„ | jdƒD ƒƒ}P qW |S )NÚ c             S   s   g | ]}d | ‘qS )z%%%2X© )Ú.0Úor,   r,   ú2/usr/lib/python3/dist-packages/httplib2/iri2uri.pyú
<listcomp><   s    zencode.<locals>.<listcomp>zutf-8)ÚordÚescape_rangeÚjoinÚencode)ÚcZretvalÚiZlowZhighr,   r,   r/   r4   5   s    r4   c             C   s^   t | tƒrZtjj| ƒ\}}}}}|jdƒjdƒ}tjj|||||fƒ} dj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.Zidnazutf-8r+   c             S   s   g | ]}t |ƒ‘qS r,   )r4   )r-   r5   r,   r,   r/   r0   L   s    ziri2uri.<locals>.<listcomp>)	Ú
isinstanceÚstrÚurllibÚparseZurlsplitr4   ÚdecodeZ
urlunsplitr3   )ÚuriÚschemeZ	authorityÚpathZqueryZfragmentr,   r,   r/   Úiri2uriA   s    
r?   Ú__main__c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestc             C   s6   ddddddddg}x|D ]}| j |t|ƒƒ qW 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_urisT   s    
zTest.test_urisc             C   s~   | 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ƒƒƒ dS )zG Test 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=â˜š#â˜„zutf-8N)rB   r?   ZassertNotEqualr4   )rC   r,   r,   r/   Útest_irib   s    zTest.test_iriN)Ú__name__Ú
__module__Ú__qualname__rD   rE   r,   r,   r,   r/   rA   R   s   rA   )r   r   )r   r   )r   r   )r	   r
   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r    )r!   r"   )r#   r$   )r%   r&   )r'   r(   )r)   r*   )Ú__doc__Ú
__author__Z__copyright__Z__contributors__Ú__version__Z__license__Z__history__Zurllib.parser9   r2   r4   r?   rF   ZunittestZTestCaserA   Úmainr,   r,   r,   r/   Ú<module>   sB   