Zw
n5 d Z ddlZddlZddlmZ dZd Zd Zej re Z
d ZneZ
e Zd Z
G d d
e Zd Zd Zd
Zd ZdZ ed Z ed Z ej e j Zd Zedk rdS 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)utilssurrogateescapec H t j r| S | d S )Nunicode_escape)r PY3decode)texts n/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/future/utils/surrogateescape.pyur s$ y -{{+,,, c H t j r| d S | S )Nlatin1)r r encode)datas r
br s# y {{8$$$r c " t | f S N)bytes)codes r
r # s UD7^^ r c | j | j | j } t | t rt | }n't | t rt | }n| n# t $ r | w xY w|| j fS )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.
) objectstartend
isinstanceUnicodeDecodeErrorreplace_surrogate_decodeUnicodeEncodeErrorreplace_surrogate_encodeNotASurrogateError)excmystringdecodeds r
surrogateescape_handlerr$ ( s z#)CG+,Hc-.. .x88GG
/
0
0 /x88GGI SWs AA( (
A5c e Zd ZdS )r N)__name__
__module____qualname__ r r
r r C s Dr r c l g }| D ]}t | }d|cxk rdk s n t d|cxk rdk r)n n&| t |dz
]|dk r&| t |dz
t t | S )z
Returns a (unicode) string, not the more logical bytes, because the codecs
register_error functionality expects this.
i )ordr append_unichrstrjoin)r" r# chr s r
r r G s
G % % 2ww ''''''''$$
T####V#####NN74&=112222
V^^NN74&=112222$$55::gr c j g }| D ]}t |t r|}nt | }d|cxk rdk r)n n&| t d|z _|dk r#| t | t
t
| S )z$
Returns a (unicode) string
r- )r intr. r/ r0 r r1 r2 )mybytesr# r3 r s r
r r d s G % % b# DDr77D44NN76D=112222
T\\NN74==)))) %$55::gr c v t dk rg }t | D ]}\ }}t | }|dk rt | }n>d|cxk rdk rn nt |dz
}nt t | ||dz d | | ~t
| S t dk rg }t | D ]\ }}t | }d |cxk rd
k rVn nSd|cxk rdk r+n n(t |dz
}| | \t t | ||dz d | d }| | t
| S | t t S )Nasciir5 i r, r- zordinal not in range(128)zutf-8r+ i zsurrogates not allowed)
FS_ENCODING enumerater. bytes_chrr r/ r r2 r FS_ERRORS)fnencodedindexr3 r ch_utf8s r
encodefilenamerE } s g "2
IE2r77Dczzt__4))))6)))))tf}--(uQw/1 1 1
NN2ww||G$$$ "2 ( (IE2r77D'''''''''T++++V+++++"4&=11BNN2&&&&,#E57,DF F F ))G,,w''''ww||G$$$yyi000r c B | t t S r )r r= r@ )rA s r
decodefilenamerG s
99[),,,r r; u [abcÿ]u [abc]c t j rdS t j t dS # t
$ r# t j t t Y dS w xY w)zH
Registers the surrogateescape error handler on Python 2 (only)
N)r r codecslookup_errorr@ LookupErrorregister_errorr$ r) r r
register_surrogateescaperM sl
y BI&&&&& B B Bi)@AAAAAABs + )AA__main__)__doc__rI sysfuturer r@ r r r chrr0 r? unichrr$ Exceptionr r r rE rG r= rA rB lookupnamerM r&