U
    X]9  ć                   @   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.0Z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   ś2/usr/lib/python3/dist-packages/httplib2/iri2uri.pyŚ
<listcomp>7   s     zencode.<locals>.<listcomp>śutf-8)ŚordŚescape_rangeŚjoinŚencode)ŚcZretvalŚiZlowZ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.Z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ŚparseZurlsplitr   ŚdecodeZ
urlunsplitr   )ŚuriZschemeZ	authorityŚpathZqueryZ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__Z__copyright__Z__contributors__Ś__version__Z__license__Zurllib.parser   r   r   r   r   ZunittestZTestCaser   Śmainr   r   r   r   Ś<module>   sB   ģ.