Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/asn1crypto/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/asn1crypto/__pycache__/_iri.cpython-35.pyc



<O�X�!�@sMdZddlmZmZmZmZddlmZddlZddl	Z	ddl
Z
ddlmZddl
mZmZmZmZmZe
jdkr�dd	lmZmZdd
lmZmZn"ddlmZmZmZmZdd
�Zdd�Zdd�Zej de�ddd�Z!dddd�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_bytesrrcCs�t|t�s*ttdt|����d}tjdkr�|jd�r�|jd�r�d}tj	d|�}|r�|j
d�}d|t|�d�}t|�}|r�||dd�}t
|dd��}nt|�}|dkrt
|j�}|j}|dk	r0|jd
�}t
|jdd�}t
|jdd�}|j}|dk	r�t|�jd
�}d}	|dk	r�|	|7}	|r�|	d|7}	|	d7}	|dk	r�|	|7}	|dk	r,|dko�|dk}
|dko
|dk}|
r,|r,|	d|7}	t
|jdd�}t
|jdd�}
t
|jdd�}|
dkr�|dkr�|dkr�d}|dkr�d}t||	||
|f�}t|t�r�|jd�}|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	^[^:]*://rrr�safez!$&'()*+,;=�ascii��:�@shttps80shttpss443z/!$&'()*+,;=@:z/?!$&'()*+,;=@:�/��latin1)rr���)�
isinstancer
�	TypeErrorrr�sys�version_info�
startswith�re�match�group�lenr�	_urlquote�scheme�hostname�encode�username�password�port�path�query�fragmentr)�valuer)Zreal_prefixZprefix_match�parsedr*r,r-r.�netlocZdefault_httpZ
default_httpsr/r0r1�output�r6�@/opt/alt/python35/lib/python3.5/site-packages/asn1crypto/_iri.py�
iri_to_uri%sd/		


$r8cCs�t|t�s*ttdt|����t|�}|j}|dk	rZ|jd�}t|j	dddg�}t|j
dddg�}|j}|r�|jd�}|j}|r�t|t
�r�|jd�}d}|dk	r||7}|r|d|7}|d7}|dk	r,||7}|dk	rL|dt|�7}t|jdd	gd
d�}t|jddd
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�remap�:�@rr�/�preserveT�&�=)rr	r rrrr)�decode�_urlunquoter,r-r*r.r
r
r/r0r1r)r2r3r)r,r-r*r.r4r/r0r1r6r6r7�
uri_to_irius<			


!rBcCsHt|j|j|j��}dd�|D�}dj|�|jfS)a>
    Error handler for decoding UTF-8 parts of a URI into an IRI. Leaves byte
    sequences encoded in %XX format, but as part of a unicode string.

    :param exc:
        The UnicodeDecodeError exception

    :return:
        A 2-element tuple of (replacement unicode string, integer index to
        resume at)
    cSsg|]}d|�qS)z%%%02xr6)�.0�numr6r6r7�
<listcomp>�s	z,_iri_utf8_errors_handler.<locals>.<listcomp>r)r�object�start�end�join)�excZ
bytes_as_ints�replacementsr6r6r7�_iri_utf8_errors_handler�s
rL�iriutf8rcs|dks|dkrdSg�tjd|�r��fdd�}tjd||�}�fdd�}tjd||�}t|jd	�d
�jd	��}t|t�s�|jd�}t��dkr��fd
d�}tjd||�}|S)a
    Quotes a unicode string for use in a URL

    :param string:
        A unicode string

    :param safe:
        A unicode string of character to not encode

    :return:
        None (if string is None) or an ASCII byte string of the quoted string
    Nrz%[0-9a-fA-F]{2}cs^t|jd��}|jdd�}x0t��D]"}|j|dt|��}q4W|S)Nrzutf-8rMz%%%02x)rr&r@�list�replace�ord)r%�byte_stringZunicode_stringZ	safe_char)rr6r7�
_try_unescape�s
 z _urlquote.<locals>._try_unescapez(?:%[0-9a-fA-F]{2})+cs#�j|jd�jd��dS)Nrr�)�appendr&r+)r%)�escapesr6r7�_extract_escape�sz"_urlquote.<locals>._extract_escapezutf-8rrrcs
�jd�S)Nr)�pop)�_)rUr6r7�_return_escape�sz!_urlquote.<locals>._return_escapes%00)r$�search�sub�urlquoter+rr	r')�stringrrRrVr5rYr6)rUrr7r(�s$r(c	Cs+|dkr|S|dkr dS|r�dddddg}i}xK|D]C}|jd	�}|||<|j|jd
�|jd
��}qHWt|�}|r�x<|D]4}|j|jd
�dt|�jd
��}q�W|jdd
�}|r'x,|j�D]\}}|j||�}qW|S)a
    Unquotes a URI portion from a byte string into unicode using UTF-8

    :param byte_string:
        A byte string of the data to unquote

    :param remap:
        A list of characters (as unicode) that should be re-mapped to a
        %XX encoding. This is used when characters are not valid in part of a
        URL.

    :param preserve:
        A bool - indicates that the chars to be remapped if they occur in
        non-hex form, should be preserved. E.g. / for URL path.

    :return:
        A unicode string
    Nrr�����rrz%%%02xzutf-8rM)rWrOr+rrPr@�items)	rQr9r=rKZpreserve_unmap�char�replacementr5�originalr6r6r7rA�s(

(
2rA)r)#�__doc__�
__future__rrrr�	encodingsr�codecsr$r!Z_errorsr�_typesr	r
rrr
r"�urlparserr�urllibrr\rr�urllib.parser8rBrL�register_errorr(rAr6r6r6r7�<module>	s""("P44