Author: Philip Jenvey <[email protected]>
Branch: 
Changeset: r63180:5f4123d40311
Date: 2013-04-09 16:23 -0700
http://bitbucket.org/pypy/pypy/changeset/5f4123d40311/

Log:    kill the cpython-like unicodehelper function names. base encode off
        unicodetype's similar function w/ shortcuts for common encodings

diff --git a/pypy/interpreter/pyparser/parsestring.py 
b/pypy/interpreter/pyparser/parsestring.py
--- a/pypy/interpreter/pyparser/parsestring.py
+++ b/pypy/interpreter/pyparser/parsestring.py
@@ -91,9 +91,9 @@
         assert 0 <= bufp <= bufq
         substr = buf[bufp:bufq]
         if rawmode:
-            v = unicodehelper.PyUnicode_DecodeRawUnicodeEscape(space, substr)
+            v = unicodehelper.decode_raw_unicode_escape(space, substr)
         else:
-            v = unicodehelper.PyUnicode_DecodeUnicodeEscape(space, substr)
+            v = unicodehelper.decode_unicode_escape(space, substr)
         return space.wrap(v)
 
     need_encoding = (encoding is not None and
@@ -103,8 +103,8 @@
     substr = s[ps : q]
     if rawmode or '\\' not in s[ps:]:
         if need_encoding:
-            w_u = space.wrap(unicodehelper.PyUnicode_DecodeUTF8(space, substr))
-            w_v = unicodehelper.PyUnicode_AsEncodedString(space, w_u, 
space.wrap(encoding))
+            w_u = space.wrap(unicodehelper.decode_utf8(space, substr))
+            w_v = unicodehelper.encode(space, w_u, encoding)
             return w_v
         else:
             return space.wrap(substr)
@@ -219,8 +219,8 @@
     # while (s < end && *s != '\\') s++; */ /* inefficient for u".."
     while ps < end and ord(s[ps]) & 0x80:
         ps += 1
-    w_u = space.wrap(unicodehelper.PyUnicode_DecodeUTF8(space, s[pt:ps]))
-    w_v = unicodehelper.PyUnicode_AsEncodedString(space, w_u, 
space.wrap(encoding))
+    w_u = space.wrap(unicodehelper.decode_utf8(space, s[pt:ps]))
+    w_v = unicodehelper.encode(space, w_u, encoding)
     v = space.str_w(w_v)
     return v, ps
 
diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -29,11 +29,12 @@
 
 # ____________________________________________________________
 
-def PyUnicode_AsEncodedString(space, w_data, w_encoding):
-    return interp_codecs.encode(space, w_data, w_encoding)
+def encode(space, w_data, encoding=None, errors='strict'):
+    from pypy.objspace.std.unicodetype import encode_object
+    return encode_object(space, w_data, encoding, errors)
 
 # These functions take and return unwrapped rpython strings and unicodes
-def PyUnicode_DecodeUnicodeEscape(space, string):
+def decode_unicode_escape(space, string):
     state = space.fromcache(interp_codecs.CodecState)
     unicodedata_handler = state.get_unicodedata_handler(space)
     result, consumed = runicode.str_decode_unicode_escape(
@@ -42,20 +43,20 @@
         unicodedata_handler=unicodedata_handler)
     return result
 
-def PyUnicode_DecodeRawUnicodeEscape(space, string):
+def decode_raw_unicode_escape(space, string):
     result, consumed = runicode.str_decode_raw_unicode_escape(
         string, len(string), "strict",
         final=True, errorhandler=decode_error_handler(space))
     return result
 
-def PyUnicode_DecodeUTF8(space, string):
+def decode_utf8(space, string):
     result, consumed = runicode.str_decode_utf_8(
         string, len(string), "strict",
         final=True, errorhandler=decode_error_handler(space),
         allow_surrogates=True)
     return result
 
-def PyUnicode_EncodeUTF8(space, uni):
+def encode_utf8(space, uni):
     return runicode.unicode_encode_utf_8(
         uni, len(uni), "strict",
         errorhandler=encode_error_handler(space),
diff --git a/pypy/module/pyexpat/interp_pyexpat.py 
b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -475,8 +475,8 @@
 
     def w_convert(self, space, s):
         if self.returns_unicode:
-            from pypy.interpreter.unicodehelper import PyUnicode_DecodeUTF8
-            return space.wrap(PyUnicode_DecodeUTF8(space, s))
+            from pypy.interpreter.unicodehelper import decode_utf8
+            return space.wrap(decode_utf8(space, s))
         else:
             return space.wrap(s)
 
diff --git a/pypy/objspace/std/marshal_impl.py 
b/pypy/objspace/std/marshal_impl.py
--- a/pypy/objspace/std/marshal_impl.py
+++ b/pypy/objspace/std/marshal_impl.py
@@ -405,11 +405,11 @@
 register(TYPE_CODE, unmarshal_pycode)
 
 def marshal_w__Unicode(space, w_unicode, m):
-    s = unicodehelper.PyUnicode_EncodeUTF8(space, space.unicode_w(w_unicode))
+    s = unicodehelper.encode_utf8(space, space.unicode_w(w_unicode))
     m.atom_str(TYPE_UNICODE, s)
 
 def unmarshal_Unicode(space, u, tc):
-    return space.wrap(unicodehelper.PyUnicode_DecodeUTF8(space, u.get_str()))
+    return space.wrap(unicodehelper.decode_utf8(space, u.get_str()))
 register(TYPE_UNICODE, unmarshal_Unicode)
 
 app = gateway.applevel(r'''
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to