????

Your IP : 3.143.168.178


Current Path : /lib/python3.6/site-packages/future/utils/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/future/utils/__pycache__/surrogateescape.cpython-36.pyc

3

�c��@s�dZddlZddlZddlmZdZdd�Zdd�ZejrHe	Z
d	d
�ZneZ
e	Zdd�Z
Gd
d�de�Zdd�Zdd�Zdd�Zdd�ZdZed�Zed�Zeje�jZdd�Zedkr�dS)z�
This is Victor Stinner's pure-Python implementation of PEP 383: the "surrogateescape" error
handler of Python 3.

Source: misc/python/surrogateescape.py in https://bitbucket.org/haypo/misc
�N)�utils�surrogateescapecCstjr
|S|jd�SdS)NZunicode_escape)r�PY3�decode)�text�r�%/usr/lib/python3.6/surrogateescape.py�usr	cCstjr|jd�S|SdS)N�latin1)rr�encode)�datarrr�bs
r
cCs
t|f�S)N)�bytes)�coderrr�<lambda>#srcCsf|j|j|j�}y0t|t�r(t|�}nt|t�r<t|�}n|�Wntk
rZ|�YnX||jfS)z�
    Pure Python implementation of the PEP 383: the "surrogateescape" error
    handler of Python 3. Undecodable bytes will be replaced by a Unicode
    character U+DCxx on decoding, and these are translated into the
    original bytes on encoding.
    )	�object�start�end�
isinstance�UnicodeDecodeError�replace_surrogate_decode�UnicodeEncodeError�replace_surrogate_encode�NotASurrogateError)�exc�mystring�decodedrrr�surrogateescape_handler(s




rc@seZdZdS)rN)�__name__�
__module__�__qualname__rrrrrCsrcCs�g}x||D]t}t|�}d|ko(dkns2t�d|koDdknr^|jt|d��q
|dkrz|jt|d��q
t�q
Wt�j|�S)z�
    Returns a (unicode) string, not the more logical bytes, because the codecs
    register_error functionality expects this.
    i�i��i�i�)�ordr�append�_unichr�str�join)rr�chrrrrrGs
rcCs~g}xl|D]d}t|t�r|}nt|�}d|ko8dknrR|jtd|��q
|dkrj|jt|��q
t�q
Wt�j|�S)z$
    Returns a (unicode) string
    ��i��)r�intr!r"r#rr$r%)Zmybytesrr&rrrrrds

rcCsJtdkr�g}xrt|�D]f\}}t|�}|dkr8t|�}n:d|koJdknr^t|d�}ntt|||dd��|j|�qWt�j|�Stdk�r:g}x�t|�D]�\}}t|�}d	|ko�d
kn�rd|ko�dkn�rt|d�}|j|�ntt|||dd��q�|jd�}|j|�q�Wt�j|�S|jtt	�SdS)N�asciir'i��i��i��zordinal not in range(128)zutf-8i�i��zsurrogates not allowed)
�FS_ENCODING�	enumerater!�	bytes_chrrr"rr%r�	FS_ERRORS)�fn�encoded�indexr&rZch_utf8rrr�encodefilename}s8



r4cCs|jtt�S)N)rr-r0)r1rrr�decodefilename�sr5r+u[abcÿ]u[abc�]cCs>tjr
dSytjt�Wn tk
r8tjtt�YnXdS)zH
    Registers the surrogateescape error handler on Python 2 (only)
    N)rr�codecs�lookup_errorr0�LookupError�register_errorrrrrr�register_surrogateescape�sr:�__main__)�__doc__r6�sysZfuturerr0r	r
r�chrr#r/Zunichrr�	Exceptionrrrr4r5r-r1r2�lookup�namer:rrrrr�<module>s0
'