
    9i                        S r SSKrSSKrSSKJr  SrS rS r\R                  (       a  \	r
S rO\r
\	rS r " S	 S
\5      rS rS rS rS rSr\" S5      r\" S5      r\R.                  " \5      R0                  rS r\S:X  a  gg)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                 R    [         R                  (       a  U $ U R                  S5      $ )Nunicode_escape)r   PY3decode)texts    \/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/future/utils/surrogateescape.pyur      s    yy{{+,,    c                 R    [         R                  (       a  U R                  S5      $ U $ )Nlatin1)r   r   encode)datas    r
   br      s    yy{{8$$r   c                     [        U 45      $ N)bytes)codes    r
   <lambda>r   #   s
    UD7^r   c                    U R                   U R                  U R                   n [        U [        5      (       a  [        U5      nO#[        U [        5      (       a  [        U5      nOU eX R                  4$ ! [         a    U ef = f)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decodeds      r
   surrogateescape_handlerr$   (   s}     zz#))CGG,Hc-...x8G/00 /x8GI WW  	s    A6  A6 'A6 6Bc                       \ rS rSrSrg)r    C    N)__name__
__module____qualname____firstlineno____static_attributes__r'   r   r
   r    r    C   s    r   r    c                 F   / nU  H  n[        U5      nSUs=::  a  S::  d   [        e  [        eSUs=::  a  S::  a"  O  OUR                  [        US-
  5      5        MX  US::  a  UR                  [        US-
  5      5        M}  [        e   [	        5       R                  U5      $ )zw
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   s       r
   r   r   G   s    
 G 2w ''$$ ($$
 T#V#NN74&=12V^NN74&=12$$' ( 5::gr   c                 :   / nU  H{  n[        U[        5      (       a  UnO[        U5      nSUs=::  a  S::  a"  O  OUR                  [	        SU-   5      5        MU  US::  a  UR                  [	        U5      5        Mw  [
        e   [        5       R                  U5      $ )z
Returns a (unicode) string
      r0      )r   intr1   r2   r3   r    r4   r5   )mybytesr#   r6   r   s       r
   r   r   d   s     G b#Dr7D44NN76D=12T\NN74=) %$! " 5::gr   c                    [         S:X  a  / n[        U 5       Hg  u  p#[        U5      nUS:  a  [        U5      nO4SUs=::  a  S::  a  O  O[        US-
  5      nO[	        [         XUS-   S5      eUR                  U5        Mi     [        5       R                  U5      $ [         S:X  a  / n[        U 5       H  u  p#[        U5      nS	Us=::  a  S
::  aI  O  OFSUs=::  a  S::  a$  O  O![        US-
  5      nUR                  U5        MQ  [	        [         XUS-   S5      eUR                  S5      nUR                  U5        M     [        5       R                  U5      $ U R                  [         [        5      $ )Nasciir8   i  r/   r0      zordinal not in range(128)zutf-8r.   i  zsurrogates not allowed)
FS_ENCODING	enumerater1   	bytes_chrr   r2   r   r5   r   	FS_ERRORS)fnencodedindexr6   r   ch_utf8s         r
   encodefilenamerH   }   sK   g "2IEr7Dczt_4)6)tf}-(uQw/1 1 NN2 ' w||G$$		 "2IEr7D''T+V+"4&=1BNN2&,#57,DF F ))G,w' ' w||G$$yyi00r   c                 6    U R                  [        [        5      $ r   )r   r@   rC   )rD   s    r
   decodefilenamerJ      s    99[),,r   r>   u   [abcÿ]u   [abc]c                      [         R                  (       a  g [        R                  " [        5        g! [
         a"    [        R                  " [        [        5         gf = f)z@
Registers the surrogateescape error handler on Python 2 (only)
N)r   r   codecslookup_errorrC   LookupErrorregister_errorr$   r'   r   r
   register_surrogateescaperP      sD     yyBI& Bi)@ABs   3 )AA__main__)__doc__rL   sysfuturer   rC   r   r   r   chrr3   rB   unichrr$   	Exceptionr    r   r   rH   rJ   r@   rD   rE   lookupnamerP   r(   r'   r   r
   <module>rZ      s     
  	
- 	99G+IGI6	 	:2%1N- AkNra6FG mmK(--	B z r   