Commits

Armin Rigo  committed f7a311f

str.partition(), str.rpartition()

  • Participants
  • Parent commits 8642262

Comments (0)

Files changed (2)

File pypy/objspace/std/bytesobject.py

             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))

File pypy/objspace/std/test/test_unicodeobject.py

         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