Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r72923:f7a311fdf0ac
Date: 2014-08-20 09:50 +0200
http://bitbucket.org/pypy/pypy/changeset/f7a311fdf0ac/

Log:    str.partition(), str.rpartition()

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
@@ -791,6 +791,20 @@
             return self_as_uni.descr_rindex(space, w_sub, w_start, w_end)
         return self._StringMethods_descr_rindex(space, w_sub, w_start, w_end)
 
+    _StringMethods_descr_partition = descr_partition
+    def descr_partition(self, space, w_sub):
+        if space.isinstance_w(w_sub, space.w_unicode):
+            self_as_uni = unicode_from_encoded_object(space, self, None, None)
+            return self_as_uni.descr_partition(space, w_sub)
+        return self._StringMethods_descr_partition(space, w_sub)
+
+    _StringMethods_descr_rpartition = descr_rpartition
+    def descr_rpartition(self, space, w_sub):
+        if space.isinstance_w(w_sub, space.w_unicode):
+            self_as_uni = unicode_from_encoded_object(space, self, None, None)
+            return self_as_uni.descr_rpartition(space, w_sub)
+        return self._StringMethods_descr_rpartition(space, w_sub)
+
     def _join_return_one(self, space, w_obj):
         return (space.is_w(space.type(w_obj), space.w_str) or
                 space.is_w(space.type(w_obj), 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
@@ -628,6 +628,13 @@
         raises(ValueError, S.rpartition, u'')
         raises(TypeError, S.rpartition, None)
 
+    def test_partition_str_unicode(self):
+        x = 'abbbd'.rpartition(u'bb')
+        assert x == (u'ab', u'bb', u'd')
+        assert map(type, x) == [unicode, unicode, unicode]
+        raises(UnicodeDecodeError, '\x80'.partition, u'')
+        raises(UnicodeDecodeError, '\x80'.rpartition, u'')
+
     def test_mul(self):
         zero = 0
         assert type(u'' * zero) == type(zero * u'') == unicode
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to