GitLab will be upgraded on June 2nd 2020 at 2.00 pm (AEDT) to 3.00 pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to local Gitlab admin team.

Commit e6a3cbb1 authored by Armin Rigo's avatar Armin Rigo

str.partition(), str.rpartition()

parent 78fb34b0
......@@ -791,6 +791,20 @@ class W_BytesObject(W_AbstractBytesObject):
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))
......
......@@ -628,6 +628,13 @@ class AppTestUnicodeString:
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment