def fsdecode(space, w_string): state = space.fromcache(interp_codecs.CodecState) if _WIN32: bytes = space.bytes_w(w_string) uni = str_decode_mbcs(bytes, len(bytes), 'strict', errorhandler=decode_error_handler(space), force_ignore=False)[0] elif _MACOSX: bytes = space.bytes_w(w_string) uni = runicode.str_decode_utf_8( bytes, len(bytes), 'surrogateescape', errorhandler=state.decode_error_handler)[0] elif state.codec_need_encodings: # bootstrap check: if the filesystem codec is implemented in # Python we cannot use it before the codecs are ready. use the # locale codec instead from pypy.module._codecs.locale import ( str_decode_locale_surrogateescape) bytes = space.bytes_w(w_string) uni = str_decode_locale_surrogateescape( bytes, errorhandler=decode_error_handler(space)) else: from pypy.module.sys.interp_encoding import getfilesystemencoding return space.call_method(w_string, 'decode', getfilesystemencoding(space), space.wrap('surrogateescape')) return space.wrap(uni)
def fsdecode(space, w_string): from pypy.module._codecs import interp_codecs state = space.fromcache(interp_codecs.CodecState) if _WIN32: bytes = space.bytes_w(w_string) uni = str_decode_mbcs(bytes, len(bytes), 'strict', errorhandler=decode_error_handler(space), force_ignore=False)[0] elif _MACOSX: bytes = space.bytes_w(w_string) uni = runicode.str_decode_utf_8_impl( bytes, len(bytes), 'surrogateescape', final=True, errorhandler=state.decode_error_handler, allow_surrogates=False)[0] elif space.sys.filesystemencoding is None or state.codec_need_encodings: # bootstrap check: if the filesystemencoding isn't initialized # or the filesystem codec is implemented in Python we cannot # use it before the codecs are ready. use the locale codec # instead from pypy.module._codecs.locale import ( str_decode_locale_surrogateescape) bytes = space.bytes_w(w_string) uni = str_decode_locale_surrogateescape( bytes, errorhandler=decode_error_handler(space)) else: from pypy.module.sys.interp_encoding import getfilesystemencoding return space.call_method(w_string, 'decode', getfilesystemencoding(space), space.newtext('surrogateescape')) return space.newunicode(uni)
def strerror(errno): """Translate an error code to a unicode message string.""" from pypy.module._codecs.locale import str_decode_locale_surrogateescape utf8, lgt = str_decode_locale_surrogateescape(os.strerror(errno)) return utf8, lgt
def strerror(errno): """Translate an error code to a message string.""" from pypy.module._codecs.locale import str_decode_locale_surrogateescape return str_decode_locale_surrogateescape(os.strerror(errno))