File: //opt/alt/python38/lib/python3.8/site-packages/asn1crypto/__pycache__/_iri.cpython-38.pyc
U
<O�X�! � @ s� d Z ddlmZmZmZmZ ddlmZ ddlZddl Z ddl
Z
ddlmZ ddl
mZmZmZmZmZ e
jdk r�dd lmZmZ dd
lmZmZ nddlmZmZmZmZ dd
� Zdd� Zdd� Ze� de� ddd�Z!ddd�Z"dS )z�
Functions to convert unicode IRIs into ASCII byte string URIs and back. Exports
the following items:
- iri_to_uri()
- uri_to_iri()
� )�unicode_literals�division�absolute_import�print_function)�idnaN� )�unwrap)�byte_cls�str_cls� type_name�
bytes_to_list� int_types)� )�urlsplit�
urlunsplit)�quote�unquote)r �unquote_to_bytesr r c C s t | t�sttdt| ����d}tjdk r�| �d�s�| �d�s�d}t� d| �}|rp|�
d�}d| t|�d� } t| �}|r�|| dd� } t
|dd � �}nt| �}|dkr�t
|j�}|j}|dk r�|�d
�}t
|jdd�}t
|jdd�}|j}|dk �r
t|��d
�}d} |dk �r:| |7 } |�r2| d| 7 } | d7 } |dk �rL| |7 } |dk �r�|dk�of|dk}
|dk�ox|dk}|
�s�|�s�| d| 7 } t
|jdd�}t
|jdd�}
t
|jdd�}|
dk�r�|dk�r�|dk�r�d}|dk�r�d}t|| ||
|f�}t |t��r|�d�}|S )z�
Normalizes and encodes a unicode IRI into an ASCII byte string URI
:param value:
A unicode string of an IRI
:return:
A byte string of the ASCII-encoded URI
z@
value must be a unicode string, not %s
N)� � zhttp://zhttps://z ^[^:]*://r r ���r z!$&'()*+,;=��safe�ascii� � :� @s https 80s httpss 443z/!$&'()*+,;=@:z/?!$&'()*+,;=@:� /� �latin1)�
isinstancer
� TypeErrorr r �sys�version_info�
startswith�re�match�group�lenr � _urlquote�scheme�hostname�encode�username�password�port�path�query�fragmentr )�valuer* Zreal_prefixZprefix_match�parsedr+ r- r. r/ �netlocZdefault_httpZ
default_httpsr0 r1 r2 �output� r7 �/_iri.py�
iri_to_uri% sf
�
r9 c C s( t | t�sttdt| ����t| �}|j}|dk r<|�d�}t|j ddgd�}t|j
ddgd�}|j}|rt|�d�}|j}|r�t |t
�s�|�d�}d}|dk r�||7 }|r�|d| 7 }|d7 }|dk r�||7 }|dk r�|dt|� 7 }t|jd gd
d�}t|jdd
gd
d�} t|j�}
t|||| |
f�S )z�
Converts an ASCII URI byte string into a unicode IRI
:param value:
An ASCII-encoded byte string of the URI
:return:
A unicode string of the IRI
z=
value must be a byte string, not %s
Nr �:�@)�remapr r �/T)r<