Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k-fix-strategies Changeset: r70980:8dabe468ecab Date: 2014-04-25 12:42 -0700 http://bitbucket.org/pypy/pypy/changeset/8dabe468ecab/
Log: provide a listview_int for bytes 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 @@ -401,9 +401,8 @@ def buffer_w(w_self, space): return StringBuffer(w_self._value) - # XXX: could provide listview_int? - #def listview_bytes(self): - # return _create_list_from_bytes(self._value) + def listview_int(self): + return _create_list_from_bytes(self._value) def ord(self, space): if len(self._value) != 1: @@ -646,8 +645,8 @@ def _create_list_from_bytes(value): # need this helper function to allow the jit to look inside and inline - # listview_bytes - return [s for s in value] + # listview_int + return [ord(s) for s in value] W_BytesObject.EMPTY = W_BytesObject('') W_BytesObject.PREBUILT = [W_BytesObject(chr(i)) for i in range(256)] 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 @@ -500,6 +500,9 @@ return w_obj.listview_int() if type(w_obj) is W_SetObject or type(w_obj) is W_FrozensetObject: return w_obj.listview_int() + if type(w_obj) is W_BytesObject: + # Python3 considers bytes strings as a list of numbers. + return w_obj.listview_int() if isinstance(w_obj, W_ListObject) and self._uses_list_iter(w_obj): return w_obj.getitems_int() return None diff --git a/pypy/objspace/std/test/test_bytesobject.py b/pypy/objspace/std/test/test_bytesobject.py --- a/pypy/objspace/std/test/test_bytesobject.py +++ b/pypy/objspace/std/test/test_bytesobject.py @@ -82,10 +82,11 @@ w_slice = space.newslice(w(1), w_None, w(2)) assert self.space.eq_w(space.getitem(w_str, w_slice), wb('el')) - def test_listview_bytes(self): + def test_listview_bytes_int(self): w_bytes = self.space.wrapbytes('abcd') # list(b'abcd') is a list of numbers assert self.space.listview_bytes(w_bytes) == None + assert self.space.listview_int(w_bytes) == [97, 98, 99, 100] class AppTestBytesObject: diff --git a/pypy/objspace/std/test/test_setobject.py b/pypy/objspace/std/test/test_setobject.py --- a/pypy/objspace/std/test/test_setobject.py +++ b/pypy/objspace/std/test/test_setobject.py @@ -136,8 +136,8 @@ w_a = W_SetObject(self.space) _initialize_set(self.space, w_a, wb("abcdefg")) - assert sorted(self.space.listview_bytes(w_a)) == list("abcdefg") - assert self.space.listview_int(w_a) is None + assert sorted(self.space.listview_int(w_a)) == [97, 98, 99, 100, 101, 102, 103] + assert self.space.listview_bytes(w_a) is None w_b = W_SetObject(self.space) _initialize_set(self.space, w_b, self.space.newlist([w(1),w(2),w(3),w(4),w(5)])) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit