Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r72919:0ff8cabf7240 Date: 2014-08-20 09:36 +0200 http://bitbucket.org/pypy/pypy/changeset/0ff8cabf7240/
Log: str.strip(), str.lstrip(), str.rstrip() 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 @@ -747,6 +747,27 @@ return self_as_uni.descr_rsplit(space, w_sep, maxsplit) return self._StringMethods_descr_rsplit(space, w_sep, maxsplit) + _StringMethods_descr_strip = descr_strip + def descr_strip(self, space, w_chars=None): + if w_chars is not None and space.isinstance_w(w_chars, space.w_unicode): + self_as_uni = unicode_from_encoded_object(space, self, None, None) + return self_as_uni.descr_strip(space, w_chars) + return self._StringMethods_descr_strip(space, w_chars) + + _StringMethods_descr_lstrip = descr_lstrip + def descr_lstrip(self, space, w_chars=None): + if w_chars is not None and space.isinstance_w(w_chars, space.w_unicode): + self_as_uni = unicode_from_encoded_object(space, self, None, None) + return self_as_uni.descr_lstrip(space, w_chars) + return self._StringMethods_descr_lstrip(space, w_chars) + + _StringMethods_descr_rstrip = descr_rstrip + def descr_rstrip(self, space, w_chars=None): + if w_chars is not None and space.isinstance_w(w_chars, space.w_unicode): + self_as_uni = unicode_from_encoded_object(space, self, None, None) + return self_as_uni.descr_rstrip(space, w_chars) + return self._StringMethods_descr_rstrip(space, w_chars) + 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 @@ -333,6 +333,17 @@ assert u'xyzzyhelloxyzzy'.lstrip('xyz') == u'helloxyzzy' assert u'xyzzyhelloxyzzy'.rstrip(u'xyz') == u'xyzzyhello' + def test_strip_str_unicode(self): + x = "--abc--".strip(u"-") + assert (x, type(x)) == (u"abc", unicode) + x = "--abc--".lstrip(u"-") + assert (x, type(x)) == (u"abc--", unicode) + x = "--abc--".rstrip(u"-") + assert (x, type(x)) == (u"--abc", unicode) + raises(UnicodeDecodeError, "\x80".strip, u"") + raises(UnicodeDecodeError, "\x80".lstrip, u"") + raises(UnicodeDecodeError, "\x80".rstrip, u"") + def test_long_from_unicode(self): assert long(u'12345678901234567890') == 12345678901234567890 assert int(u'12345678901234567890') == 12345678901234567890 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit