Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: unicode-utf8
Changeset: r93127:b89046216269
Date: 2017-11-23 03:14 +0000
http://bitbucket.org/pypy/pypy/changeset/b89046216269/

Log:    Add (back) convenience methods space.newunicode(),
        space.new_from_utf8() and space.unicode_w()

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -272,7 +272,7 @@
         self._typed_unwrap_error(space, "unicode")
 
     def convert_to_w_unicode(self, space):
-        self._typed_unwrap_error(space, "unicode")        
+        self._typed_unwrap_error(space, "unicode")
 
     def bytearray_list_of_chars_w(self, space):
         self._typed_unwrap_error(space, "bytearray")
@@ -1759,6 +1759,11 @@
 
     def utf8_w(self, w_obj):
         return w_obj.utf8_w(self)
+
+    def unicode_w(self, w_obj):
+        # XXX: kill me!
+        return w_obj.utf8_w(self).decode('utf-8')
+
     def convert_to_w_unicode(self, w_obj):
         return w_obj.convert_to_w_unicode(self)
 
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -367,10 +367,23 @@
         assert isinstance(utf8s, str)
         return W_UnicodeObject(utf8s, length, flag)
 
+    def new_from_utf8(self, utf8s):
+        # XXX: kill me!
+        assert isinstance(utf8s, str)
+        length, flag = rutf8.check_utf8(utf8s, True)
+        return W_UnicodeObject(utf8s, length, flag)
+
     def newfilename(self, s):
         assert isinstance(s, str) # on pypy3, this decodes the byte string
         return W_BytesObject(s)   # with the filesystem encoding
 
+    def newunicode(self, unistr):
+        # XXX: kill me!
+        assert isinstance(unistr, unicode)
+        utf8s = unistr.encode("utf-8")
+        length, flag = rutf8.check_utf8(utf8s, True)
+        return self.newutf8(utf8s, length, flag)
+
     def type(self, w_obj):
         jit.promote(w_obj.__class__)
         return w_obj.getclass(self)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to