Author: Alex Gaynor <alex.gay...@gmail.com> Branch: Changeset: r71687:ea5040e38901 Date: 2014-05-23 10:23 -0500 http://bitbucket.org/pypy/pypy/changeset/ea5040e38901/
Log: merged upstream diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py --- a/pypy/objspace/std/memoryobject.py +++ b/pypy/objspace/std/memoryobject.py @@ -5,7 +5,7 @@ from rpython.rlib.buffer import Buffer, SubBuffer from pypy.interpreter.baseobjspace import W_Root -from pypy.interpreter.error import OperationError +from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.gateway import interp2app from pypy.interpreter.typedef import TypeDef, GetSetProperty @@ -61,15 +61,6 @@ def getlength(self): return self.buf.getlength() - def getslice(self, start, stop): - if start < 0: - start = 0 - size = stop - start - if size < 0: - size = 0 - buf = SubBuffer(self.buf, start, size) - return W_MemoryView(buf) - def descr_tobytes(self, space): return space.wrap(self.as_str()) @@ -81,25 +72,25 @@ return space.newlist(result) def descr_getitem(self, space, w_index): - start, stop, step = space.decode_index(w_index, self.getlength()) + start, stop, step, size = space.decode_index4(w_index, self.getlength()) if step not in (0, 1): - raise OperationError(space.w_NotImplementedError, space.wrap("")) + raise oefmt(space.w_NotImplementedError, "") if step == 0: # index only return space.wrap(self.buf.getitem(start)) - res = self.getslice(start, stop) - return space.wrap(res) + else: + buf = SubBuffer(self.buf, start, size) + return W_MemoryView(buf) def descr_setitem(self, space, w_index, w_obj): if self.buf.readonly: - raise OperationError(space.w_TypeError, space.wrap( - "cannot modify read-only memory")) - start, stop, step, size = space.decode_index4(w_index, self.buf.getlength()) + raise oefmt(space.w_TypeError, "cannot modify read-only memory") + start, stop, step, size = space.decode_index4(w_index, self.getlength()) if step not in (0, 1): - raise OperationError(space.w_NotImplementedError, space.wrap("")) + raise oefmt(space.w_NotImplementedError, "") value = space.buffer_w(w_obj, space.BUF_CONTIG_RO) if value.getlength() != size: - raise OperationError(space.w_ValueError, space.wrap( - "cannot modify size of memoryview object")) + raise oefmt(space.w_ValueError, + "cannot modify size of memoryview object") if step == 0: # index only self.buf.setitem(start, value.getitem(0)) elif step == 1: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit