3
sd9  ã               @   sŠ   d Z dZdZg ZdZdZddlZd6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIgZd/d0„ Z	d1d2„ Z
ed3kr†ddlZG d4d5„ d5ejƒZejƒ  dS )JzConverts an IRI to a URI.z!Joe Gregorio (joe@bitworking.org)zCopyright 2006, Joe Gregorioz1.0.0Ú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,   ú4/tmp/pip-build-7vycvbft/httplib2/httplib2/iri2uri.pyú
<listcomp>7   s    zencode.<locals>.<listcomp>zutf-8)ÚordÚescape_rangeÚjoinÚencode)ÚcÚretvalÚiÚlowÚhighr,   r,   r/   r4   0   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.Úidnazutf-8r+   c             S   s   g | ]}t |ƒ‘qS r,   )r4   )r-   r5   r,   r,   r/   r0   G   s    ziri2uri.<locals>.<listcomp>)	Ú
isinstanceÚstrÚurllibÚparseÚurlsplitr4   ÚdecodeÚ
urlunsplitr3   )ÚuriÚschemeÚ	authorityÚpathÚqueryÚfragmentr,   r,   r/   Úiri2uri<   s    
rH   Ú__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)ÚassertEqualrH   )ÚselfZ	invariantrB   r,   r,   r/   Ú	test_urisO   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 )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=â˜š#â˜„zutf-8N)rK   rH   ZassertNotEqualr4   )rL   r,   r,   r/   Útest_iri^   s(    



zTest.test_iriN)Ú__name__Ú
__module__Ú__qualname__rM   rN   r,   r,   r,   r/   rJ   N   s   rJ   )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__Ú__copyright__Z__contributors__Ú__version__Ú__license__Úurllib.parser=   r2   r4   rH   rO   ZunittestZTestCaserJ   Úmainr,   r,   r,   r/   Ú<module>   s@   .