Author: Armin Rigo <[email protected]>
Branch:
Changeset: r72922:864226266f8c
Date: 2014-08-20 09:46 +0200
http://bitbucket.org/pypy/pypy/changeset/864226266f8c/
Log: str.replace()
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
@@ -707,19 +707,7 @@
new_is_unicode = space.isinstance_w(w_new, space.w_unicode)
if old_is_unicode or new_is_unicode:
self_as_uni = unicode_from_encoded_object(space, self, None, None)
- if not old_is_unicode:
- w_old = unicode_from_encoded_object(space, w_old, None, None)
- if not new_is_unicode:
- w_new = unicode_from_encoded_object(space, w_new, None, None)
- input = self_as_uni._val(space)
- sub = self_as_uni._op_val(space, w_old)
- by = self_as_uni._op_val(space, w_new)
- try:
- res = replace(input, sub, by, count)
- except OverflowError:
- raise oefmt(space.w_OverflowError,
- "replace string is too long")
- return self_as_uni._new(res)
+ return self_as_uni.descr_replace(space, w_old, w_new, count)
return self._StringMethods_descr_replace(space, w_old, w_new, count)
_StringMethods_descr_join = descr_join
diff --git a/pypy/objspace/std/test/test_unicodeobject.py
b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -956,10 +956,12 @@
assert not u'a'.isnumeric()
assert u'\u2460'.isnumeric() # CIRCLED DIGIT ONE
- def test_replace_autoconvert(self):
+ def test_replace_str_unicode(self):
res = 'one!two!three!'.replace(u'!', u'@', 1)
assert res == u'one@two!three!'
assert type(res) == unicode
+ raises(UnicodeDecodeError, '\x80'.replace, 'a', u'b')
+ raises(UnicodeDecodeError, '\x80'.replace, u'a', 'b')
def test_join_subclass(self):
class UnicodeSubclass(unicode):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit