Author: Armin Rigo <ar...@tunes.org> Branch: fix-strbuf Changeset: r78712:8736f18f1529 Date: 2015-07-29 17:21 +0200 http://bitbucket.org/pypy/pypy/changeset/8736f18f1529/
Log: Fixes diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py --- a/pypy/module/cpyext/unicodeobject.py +++ b/pypy/module/cpyext/unicodeobject.py @@ -196,7 +196,6 @@ def PyUnicode_GET_SIZE(space, w_obj): """Return the size of the object. o has to be a PyUnicodeObject (not checked).""" - assert isinstance(w_obj, unicodeobject.W_UnicodeObject) return space.len_w(w_obj) @cpython_api([PyObject], rffi.CWCHARP, error=CANNOT_FAIL) diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py --- a/pypy/objspace/std/bytesobject.py +++ b/pypy/objspace/std/bytesobject.py @@ -561,9 +561,10 @@ @staticmethod def _use_rstr_ops(space, w_other): - from pypy.objspace.std.unicodeobject import W_UnicodeObject + from pypy.objspace.std.unicodeobject import W_AbstractUnicodeObject + W_AbstractUnicodeObject return (isinstance(w_other, W_AbstractBytesObject) or - isinstance(w_other, W_UnicodeObject)) + isinstance(w_other, W_AbstractUnicodeObject)) @staticmethod def _op_val(space, w_other): @@ -760,12 +761,12 @@ _StringMethods_descr_contains = descr_contains def descr_contains(self, space, w_sub): if space.isinstance_w(w_sub, space.w_unicode): - from pypy.objspace.std.unicodeobject import W_UnicodeObject - assert isinstance(w_sub, W_UnicodeObject) + from pypy.objspace.std.unicodeobject import W_AbstractUnicodeObject + assert isinstance(w_sub, W_AbstractUnicodeObject) self_as_unicode = unicode_from_encoded_object(space, self, None, None) return space.newbool( - self_as_unicode._value.find(w_sub._value) >= 0) + self_as_unicode._value.find(w_sub.unicode_w(space)) >= 0) return self._StringMethods_descr_contains(space, w_sub) _StringMethods_descr_replace = descr_replace 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 @@ -8,7 +8,7 @@ from pypy.interpreter.pycode import PyCode from pypy.interpreter import unicodehelper from pypy.objspace.std.boolobject import W_BoolObject -from pypy.objspace.std.bytesobject import W_BytesObject +from pypy.objspace.std.bytesobject import W_AbstractBytesObject from pypy.objspace.std.complexobject import W_ComplexObject from pypy.objspace.std.dictmultiobject import W_DictMultiObject from pypy.objspace.std.intobject import W_IntObject @@ -19,7 +19,7 @@ from pypy.objspace.std.setobject import W_FrozensetObject, W_SetObject from pypy.objspace.std.tupleobject import W_AbstractTupleObject from pypy.objspace.std.typeobject import W_TypeObject -from pypy.objspace.std.unicodeobject import W_UnicodeObject +from pypy.objspace.std.unicodeobject import W_AbstractUnicodeObject TYPE_NULL = '0' @@ -244,7 +244,7 @@ return space.newcomplex(real, imag) -@marshaller(W_BytesObject) +@marshaller(W_AbstractBytesObject) def marshal_bytes(space, w_str, m): s = space.str_w(w_str) if m.version >= 1 and space.is_interned_str(s): @@ -394,7 +394,7 @@ name, firstlineno, lnotab, freevars, cellvars) -@marshaller(W_UnicodeObject) +@marshaller(W_AbstractUnicodeObject) def marshal_unicode(space, w_unicode, m): s = unicodehelper.encode_utf8(space, space.unicode_w(w_unicode)) m.atom_str(TYPE_UNICODE, s) diff --git a/pypy/objspace/std/test/test_unibufobject.py b/pypy/objspace/std/test/test_unibufobject.py --- a/pypy/objspace/std/test/test_unibufobject.py +++ b/pypy/objspace/std/test/test_unibufobject.py @@ -108,3 +108,15 @@ a += u'bc' assert a.startswith('abcb') assert not a.startswith('1234') + + def test_str_contains_u(self): + a = u'abc' + a += u'bc' + assert a in '--abcbc--' + assert a not in '--abcBc--' + + def test_int_unicode(self): + a = u'12' + a += u'3' + assert int(a) == 123 + assert long(a) == 123 diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -771,8 +771,7 @@ spec = space.unicode_w(w_format_spec) formatter = newformat.unicode_formatter(space, spec) self2 = unicode_from_object(space, self) - assert isinstance(self2, W_UnicodeObject) - return formatter.format_string(self2._value) + return formatter.format_string(self2.unicode_w(space)) def descr_mod(self, space, w_values): return mod_format(space, self, w_values, do_unicode=True) @@ -977,11 +976,12 @@ raise oefmt(space.w_TypeError, "decoding bytearray is not supported") w_retval = decode_object(space, w_obj, encoding, errors) - if not space.isinstance_w(w_retval, space.w_unicode): - raise oefmt(space.w_TypeError, - "decoder did not return an unicode object (type '%T')", - w_retval) - assert isinstance(w_retval, W_UnicodeObject) + if not isinstance(w_retval, W_UnicodeObject): + if not space.isinstance_w(w_retval, space.w_unicode): + raise oefmt(space.w_TypeError, + "decoder did not return an unicode object (type '%T')", + w_retval) + w_retval = W_UnicodeObject(w_retval.unicode_w(space)) return w_retval @@ -1115,9 +1115,9 @@ # Helper for converting int/long def unicode_to_decimal_w(space, w_unistr): - if not isinstance(w_unistr, W_UnicodeObject): + if not space.isinstance_w(w_unistr, space.w_unicode): raise oefmt(space.w_TypeError, "expected unicode, got '%T'", w_unistr) - unistr = w_unistr._value + unistr = w_unistr.unicode_w(space) result = ['\0'] * len(unistr) digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit