o
    0ÿ¿cÑ  ã                   @   sÂ   d Z ddlZddlZddlmZ dZdd„ Zdd„ Zejr$e	Z
d	d
„ ZneZ
e	Zdd„ ZG dd„ deƒZdd„ Zdd„ Zdd„ Zdd„ ZdZedƒZedƒZe e¡jZdd„ Zedkr_	 dS dS )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 jr| S |  d¡S )NÚunicode_escape)r   ÚPY3Údecode)Útext© r   úi/var/www/html/portale_awareness/portale-venv/lib/python3.10/site-packages/future/utils/surrogateescape.pyÚu   s   
r
   c                 C   s   t jr|  d¡S | S )NÚlatin1)r   r   Úencode)Údatar   r   r	   Úb   s   
r   c                 C   s
   t | fƒS ©N)Úbytes)Úcoder   r   r	   Ú<lambda>#   s   
 r   c                 C   s`   | j | j| j… }zt| tƒrt|ƒ}nt| tƒrt|ƒ}n| ‚W n	 ty*   | ‚w || jfS )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 Zd ZdS )r   N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r	   r   C   s    r   c                 C   sˆ   g }| D ]9}t |ƒ}d|  krdkst‚ t‚d|  kr"dkr.n n
| t|d ƒ¡ q|dkr<| t|d ƒ¡ qt‚tƒ  |¡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   sx   g }| D ]1}t |tƒr|}nt|ƒ}d|  krdkr(n n
| td| ƒ¡ q|dkr4| t|ƒ¡ qt‚tƒ  |¡S )z$
    Returns a (unicode) string
    é€   éÿ   r%   é   )r   Úintr&   r'   r(   r   r)   r*   )Úmybytesr   r+   r   r   r   r	   r   d   s   
r   c                 C   s6  t dkrDg }t| ƒD ]3\}}t|ƒ}|dk rt|ƒ}nd|  kr%dkr.n nt|d ƒ}n
tt | ||d dƒ‚| |¡ q
tƒ  |¡S t dkr•g }t| ƒD ]@\}}t|ƒ}d	|  kr`d
kr„n n"d|  krldkrzn nt|d ƒ}| |¡ qNtt | ||d dƒ‚| d¡}| |¡ qNtƒ  |¡S |  t t	¡S )NÚasciir,   i€Ü  r$   r%   é   zordinal not in range(128)zutf-8r#   iÿß  zsurrogates not allowed)
ÚFS_ENCODINGÚ	enumerater&   Ú	bytes_chrr   r'   r   r*   r   Ú	FS_ERRORS)ÚfnÚencodedÚindexr+   r   Úch_utf8r   r   r	   Úencodefilename}   s<   

þþ
r;   c                 C   s   |   tt¡S r   )r   r3   r6   )r7   r   r   r	   Údecodefilename¤   s   r<   r1   u   [abcÃ¿]u   [abcí³¿]c                   C   s<   t jrdS zt t¡ W dS  ty   t tt¡ Y dS w )zH
    Registers the surrogateescape error handler on Python 2 (only)
    N)r   r   ÚcodecsÚlookup_errorr6   ÚLookupErrorÚregister_errorr   r   r   r   r	   Úregister_surrogateescape±   s   ÿrA   Ú__main__)Ú__doc__r=   ÚsysÚfuturer   r6   r
   r   r   Úchrr(   r5   Úunichrr   Ú	Exceptionr   r   r   r;   r<   r3   r7   r8   ÚlookupÚnamerA   r    r   r   r   r	   Ú<module>   s0    	
'ÿ