[pypy-commit] pypy default: move unicode_w from W_StringObject up to W_AbstractStringObject; this way, it is automatically used also by ropes, which fixes test_unicode_join_str_arg_utf8
antocuni
noreply at buildbot.pypy.org
Thu Mar 22 21:47:35 CET 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r53930:d148511060f8
Date: 2012-03-22 21:47 +0100
http://bitbucket.org/pypy/pypy/changeset/d148511060f8/
Log: move unicode_w from W_StringObject up to W_AbstractStringObject;
this way, it is automatically used also by ropes, which fixes
test_unicode_join_str_arg_utf8
diff --git a/pypy/objspace/std/ropeobject.py b/pypy/objspace/std/ropeobject.py
--- a/pypy/objspace/std/ropeobject.py
+++ b/pypy/objspace/std/ropeobject.py
@@ -41,11 +41,6 @@
return w_self
return W_RopeObject(w_self._node)
- def unicode_w(w_self, space):
- # XXX should this use the default encoding?
- from pypy.objspace.std.unicodetype import plain_str2unicode
- return plain_str2unicode(space, w_self._node.flatten_string())
-
W_RopeObject.EMPTY = W_RopeObject(rope.LiteralStringNode.EMPTY)
W_RopeObject.PREBUILT = [W_RopeObject(rope.LiteralStringNode.PREBUILT[i])
for i in range(256)]
diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -37,6 +37,20 @@
return None
return space.wrap(compute_unique_id(space.str_w(self)))
+ def unicode_w(w_self, space):
+ # Use the default encoding.
+ from pypy.objspace.std.unicodetype import unicode_from_string, \
+ decode_object
+ w_defaultencoding = space.call_function(space.sys.get(
+ 'getdefaultencoding'))
+ from pypy.objspace.std.unicodetype import _get_encoding_and_errors, \
+ unicode_from_string, decode_object
+ encoding, errors = _get_encoding_and_errors(space, w_defaultencoding,
+ space.w_None)
+ if encoding is None and errors is None:
+ return space.unicode_w(unicode_from_string(space, w_self))
+ return space.unicode_w(decode_object(space, w_self, encoding, errors))
+
class W_StringObject(W_AbstractStringObject):
from pypy.objspace.std.stringtype import str_typedef as typedef
@@ -55,20 +69,6 @@
def str_w(w_self, space):
return w_self._value
- def unicode_w(w_self, space):
- # Use the default encoding.
- from pypy.objspace.std.unicodetype import unicode_from_string, \
- decode_object
- w_defaultencoding = space.call_function(space.sys.get(
- 'getdefaultencoding'))
- from pypy.objspace.std.unicodetype import _get_encoding_and_errors, \
- unicode_from_string, decode_object
- encoding, errors = _get_encoding_and_errors(space, w_defaultencoding,
- space.w_None)
- if encoding is None and errors is None:
- return space.unicode_w(unicode_from_string(space, w_self))
- return space.unicode_w(decode_object(space, w_self, encoding, errors))
-
registerimplementation(W_StringObject)
W_StringObject.EMPTY = W_StringObject('')
More information about the pypy-commit
mailing list