File: //usr/local/lib/python3.9/site-packages/future/utils/__pycache__/surrogateescape.cpython-39.pyc
a
q�dg� � @ s� d Z ddlZddlZddlmZ dZdd� Zdd� ZejrHe Z
d d
� ZneZ
e Zdd� Z
G d
d� de�Zdd� Zdd� Zdd� Zdd� ZdZed�Zed�Ze�e�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�surrogateescapec C s t jr
| S | �d�S d S )N�unicode_escape)r �PY3�decode)�text� r �F/usr/local/lib/python3.9/site-packages/future/utils/surrogateescape.py�u s r
c C s t jr| �d�S | S d S )N�latin1)r r �encode)�datar r r �b s
r c C s
t | f�S �N)�bytes)�coder r r �<lambda># � r c C sd | j | j| j� }z0t| t�r(t|�}nt| t�r<t|�}n| �W n tyX | �Y n0 || 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�decodedr r r �surrogateescape_handler( s
r c @ s e Zd ZdS )r N)�__name__�
__module__�__qualname__r r r r r C s r c C s� g }| D ]r}t |�}d| kr(dks.n t�d| krBdkrZn n|�t|d �� q|dkrv|�t|d �� qt�qt� �|�S )z�
Returns a (unicode) string, not the more logical bytes, because the codecs
register_error functionality expects this.
� � �� � � i� )�ordr �append�_unichr�str�join)r r �chr r r r r G s r c C sz g }| D ]d}t |t�r|}nt|�}d| kr8dkrPn n|�td| �� q|dkrh|�t|�� qt�qt� �|�S )z$
Returns a (unicode) string
� � r&