Author: Manuel Jacob
Branch: refactor-str-types
Changeset: r65777:fcbbf370c6ac
Date: 2013-07-29 14:36 +0200
http://bitbucket.org/pypy/pypy/changeset/fcbbf370c6ac/
Log: Add auto-convertion method descr_contains() in W_BytesObject.
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
@@ -204,6 +204,12 @@
return self_as_unicode._endswith(space, self_as_unicode._value,
w_suffix, start, end)
return StringMethods._endswith(self, space, value, w_suffix, start,
end)
+ def descr_contains(self, space, w_sub):
+ if space.isinstance_w(w_sub, space.w_unicode):
+ self_as_unicode = unicode_from_encoded_object(space, self, None,
None)
+ return
space.newbool(self_as_unicode._value.find(self._op_val(space, w_sub)) >= 0)
+ return StringMethods.descr_contains(self, space, w_sub)
+
@unwrap_spec(count=int)
def descr_replace(self, space, w_old, w_new, count=-1):
old_is_unicode = space.isinstance_w(w_old, space.w_unicode)
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
@@ -86,6 +86,7 @@
def test_contains(self):
assert u'a' in 'abc'
assert 'a' in u'abc'
+ raises(UnicodeDecodeError, "u'\xe2' in 'g\xe2teau'")
def test_splitlines(self):
assert u''.splitlines() == []
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit