Author: Matti Picus <matti.pi...@gmail.com> Branch: unicode-utf8-py3 Changeset: r94847:e8413e4a1934 Date: 2018-07-11 06:51 -0700 http://bitbucket.org/pypy/pypy/changeset/e8413e4a1934/
Log: small tweaks, copy partition from py3.5 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 @@ -404,9 +404,9 @@ _KIND1 = "byte" _KIND2 = "bytes" - def __init__(self, str): - assert str is not None - self._value = str + def __init__(self, s): + assert s is not None + self._value = s def __repr__(self): """representation for debugging purposes""" diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -327,7 +327,7 @@ return W_ListObject.newlist_bytes(self, list_s) def newlist_text(self, list_t): - return self.newlist_utf8([decode_utf8sp(self, s) for s in list_t]) + return self.newlist_utf8([decode_utf8sp(self, s)[0] for s in list_t]) def newlist_utf8(self, list_u, is_ascii=True): # TODO ignoring is_ascii, is that correct? @@ -762,7 +762,7 @@ if not e.match(self, self.w_TypeError): raise else: - classname = b'%s.%s' % (modulename, classname) + classname = u'%s.%s' % (modulename.decode('utf8'), classname) else: classname = w_type.name.decode('utf-8') return classname diff --git a/pypy/objspace/std/stringmethods.py b/pypy/objspace/std/stringmethods.py --- a/pypy/objspace/std/stringmethods.py +++ b/pypy/objspace/std/stringmethods.py @@ -478,39 +478,56 @@ from pypy.objspace.std.bytearrayobject import W_BytearrayObject value = self._val(space) - sub = _get_buffer(space, w_sub) - sublen = sub.getlength() - if sublen == 0: - raise oefmt(space.w_ValueError, "empty separator") + if self._use_rstr_ops(space, w_sub): + sub = self._op_val(space, w_sub) + sublen = len(sub) + if sublen == 0: + raise oefmt(space.w_ValueError, "empty separator") - pos = find(value, sub, 0, len(value)) - if pos != -1 and isinstance(self, W_BytearrayObject): - w_sub = self._new_from_buffer(sub) + pos = value.find(sub) + else: + sub = space.readbuf_w(w_sub) + sublen = sub.getlength() + if sublen == 0: + raise oefmt(space.w_ValueError, "empty separator") + + pos = find(value, sub, 0, len(value)) + if pos != -1 and isinstance(self, W_BytearrayObject): + w_sub = self._new_from_buffer(sub) if pos == -1: - self = self._new(value) + if isinstance(self, W_BytearrayObject): + self = self._new(value) return space.newtuple([self, self._empty(), self._empty()]) else: return space.newtuple( [self._sliced(space, value, 0, pos, self), w_sub, self._sliced(space, value, pos + sublen, len(value), self)]) - # This is not used for W_UnicodeObject. def descr_rpartition(self, space, w_sub): from pypy.objspace.std.bytearrayobject import W_BytearrayObject value = self._val(space) - sub = _get_buffer(space, w_sub) - sublen = sub.getlength() - if sublen == 0: - raise oefmt(space.w_ValueError, "empty separator") + if self._use_rstr_ops(space, w_sub): + sub = self._op_val(space, w_sub) + sublen = len(sub) + if sublen == 0: + raise oefmt(space.w_ValueError, "empty separator") - pos = rfind(value, sub, 0, len(value)) - if pos != -1 and isinstance(self, W_BytearrayObject): - w_sub = self._new_from_buffer(sub) + pos = value.rfind(sub) + else: + sub = space.readbuf_w(w_sub) + sublen = sub.getlength() + if sublen == 0: + raise oefmt(space.w_ValueError, "empty separator") + + pos = rfind(value, sub, 0, len(value)) + if pos != -1 and isinstance(self, W_BytearrayObject): + w_sub = self._new_from_buffer(sub) if pos == -1: - self = self._new(value) + if isinstance(self, W_BytearrayObject): + self = self._new(value) return space.newtuple([self._empty(), self._empty(), self]) else: return space.newtuple( diff --git a/pypy/objspace/std/test/test_stdobjspace.py b/pypy/objspace/std/test/test_stdobjspace.py --- a/pypy/objspace/std/test/test_stdobjspace.py +++ b/pypy/objspace/std/test/test_stdobjspace.py @@ -84,7 +84,7 @@ from pypy.objspace.std.unicodeobject import W_UnicodeObject w_x = self.space.wrap('foo') assert isinstance(w_x, W_UnicodeObject) - assert w_x._value == u'foo' + assert w_x._utf8 == 'foo' # # calling space.wrap() on a byte string which is not ASCII should # never happen. Howeven it might happen while the py3k port is not @@ -93,4 +93,4 @@ from pypy.objspace.std.unicodeobject import W_UnicodeObject w_x = self.space.wrap('foo\xF0') assert isinstance(w_x, W_UnicodeObject) - assert w_x._value == u'foo\ufffd' + assert w_x._utf8 == 'foo\uxF0' _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit