[pypy-commit] pypy unicode-utf8: fix from merge, add mcbs variants? (mattip, ronan)

mattip pypy.commits at gmail.com
Sun Mar 18 09:05:40 EDT 2018


Author: Matti Picus <matti.picus at gmail.com>
Branch: unicode-utf8
Changeset: r93987:d5f6267bf47b
Date: 2018-03-18 14:04 +0100
http://bitbucket.org/pypy/pypy/changeset/d5f6267bf47b/

Log:	fix from merge, add mcbs variants? (mattip, ronan)

diff --git a/pypy/interpreter/test/test_unicodehelper.py b/pypy/interpreter/test/test_unicodehelper.py
--- a/pypy/interpreter/test/test_unicodehelper.py
+++ b/pypy/interpreter/test/test_unicodehelper.py
@@ -2,8 +2,6 @@
 from hypothesis import given, strategies
 import struct
 import sys
-from pypy.interpreter.unicodehelper import (
-    encode_utf8, decode_utf8, unicode_encode_utf_32_be)
 
 from rpython.rlib import rutf8
 
diff --git a/pypy/interpreter/unicodehelper.py b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -221,6 +221,20 @@
                 pos = rutf8._pos_at_index(s, newindex)
     return result.build()
 
+if sys.platform == 'win32':
+    def utf8_encode_mbcs(s, errors, errorhandler):
+        from rpython.rlib import runicode
+        slen = len(s)
+        res = runicode.unicode_encode_mbcs(s, slen, errors, errorhandler)
+        return res.decode('utf8')
+        
+    def str_decode_mbcs(s, errors, errorhandler):
+        from rpython.rlib import runicode
+        slen = len(s)
+        res, size = runicode.str_decode_mbcs(s, slen, errors=errors,
+                                           errorhandler=errorhandler)
+        return res.encode('utf8'), size, len(res)
+
 def str_decode_utf8(s, errors, final, errorhandler):
     """ Same as checking for the valid utf8, but we know the utf8 is not
     valid so we're trying to either raise or pack stuff with error handler.


More information about the pypy-commit mailing list