[pypy-commit] pypy unicode-utf8-py3: blindly try to fix win32 translation
mattip
pypy.commits at gmail.com
Sun Sep 9 05:56:00 EDT 2018
Author: Matti Picus <matti.picus at gmail.com>
Branch: unicode-utf8-py3
Changeset: r95084:3c45a9eb3419
Date: 2018-09-09 12:54 +0300
http://bitbucket.org/pypy/pypy/changeset/3c45a9eb3419/
Log: blindly try to fix win32 translation
diff --git a/pypy/interpreter/unicodehelper.py b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -10,11 +10,6 @@
_WIN32 = sys.platform == 'win32'
_MACOSX = sys.platform == 'darwin'
-if _WIN32:
- from rpython.rlib.runicode import str_decode_mbcs, unicode_encode_mbcs
-else:
- # Workaround translator's confusion
- str_decode_mbcs = unicode_encode_mbcs = lambda *args, **kwargs: None
@specialize.memo()
def decode_error_handler(space):
@@ -317,7 +312,7 @@
pos = rutf8._pos_at_index(s, newindex)
return result.build()
-if sys.platform == 'win32':
+if _WIN32:
def utf8_encode_mbcs(s, errors, errorhandler):
s = s.decode('utf-8')
if errorhandler is None:
@@ -325,12 +320,12 @@
res = unicode_encode_mbcs(s, slen, errors, errorhandler)
return res
- def str_decode_mbcs(s, errors, final, errorhandler):
+ def str_decode_mbcs(s, errors, final, errorhandler, force_ignore=True):
slen = len(s)
if errorhandler is None:
errorhandler = decode_error_handler(space)
- res, size = str_decode_mbcs(s, slen, final=final, errors=errors,
- errorhandler=errorhandler)
+ res, size = runicode.str_decode_mbcs(s, slen, final=final, errors=errors,
+ errorhandler=errorhandler, force_ignore=force_ignore)
res_utf8 = runicode.unicode_encode_utf_8(res, len(res), 'strict')
return res_utf8, len(res)
diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -703,31 +703,9 @@
]:
make_decoder_wrapper(decoder)
-if hasattr(runicode, 'str_decode_mbcs'):
- # mbcs functions are not regular, because we have to pass
- # "force_ignore/replace=False"
- @unwrap_spec(uni=unicode, errors='text_or_none')
- def mbcs_encode(space, uni, errors="strict"):
- if errors is None:
- errors = 'strict'
- state = space.fromcache(CodecState)
- result = runicode.unicode_encode_mbcs(
- uni, len(uni), errors, state.encode_error_handler,
- force_replace=False)
- return space.newtuple([space.newbytes(result), space.newint(len(uni))])
-
- @unwrap_spec(string='bufferstr', errors='text_or_none',
- w_final=WrappedDefault(False))
- def mbcs_decode(space, string, errors="strict", w_final=None):
- if errors is None:
- errors = 'strict'
- final = space.is_true(w_final)
- state = space.fromcache(CodecState)
- result, length, pos = runicode.str_decode_mbcs(
- string, len(string), errors,
- final, state.decode_error_handler,
- force_ignore=False)
- return space.newtuple([space.newtext(result, length), space.newint(pos)])
+if hasattr(unicodehelper, 'str_decode_mbcs'):
+ make_encoder_wrapper('mbcs_encode')
+ make_decoder_wrapper('mbcs_decode')
# utf-8 functions are not regular, because we have to pass
# "allow_surrogates=False"
More information about the pypy-commit
mailing list