B ,]@sdZddlZddlZddlmZdZddZddZejrHe Z d d Z ne Z e Z d d Z Gd ddeZddZddZddZddZdZedZedZeejZddZedkrdS)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)utilssurrogateescapecCstjr |S|dSdS)NZunicode_escape)rPY3decode)textrC/tmp/pip-target-9_2btsuh/lib/python/future/utils/surrogateescape.pyusr cCstjr|dS|SdS)Nlatin1)rrencode)datarrrbs r cCs t|fS)N)bytes)coderrr#rcCsf|j|j|j}y0t|tr(t|}nt|trtjr dSyttWn tk r8tttYnXdS)zH Registers the surrogateescape error handler on Python 2 (only) N)rrcodecs lookup_errorr1 LookupErrorregister_errorrrrrrregister_surrogateescapes r;__main__)__doc__r7sysfuturerr1r r rchrr$r0unichrr Exceptionrrrr5r6r.r2r3lookupnamer;rrrrrs0  '