Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r71283:01e1b2dbf81e
Date: 2014-05-05 12:07 -0700
http://bitbucket.org/pypy/pypy/changeset/01e1b2dbf81e/
Log: merge upstream
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -202,30 +202,6 @@
return w_result.buffer_w(space, flags)
raise TypeError
- def readbuf_w(self, space):
- w_impl = space.lookup(self, '__buffer__')
- if w_impl is not None:
- w_result = space.get_and_call_function(w_impl, self)
- if space.isinstance_w(w_result, space.w_memoryview):
- return w_result.readbuf_w(space)
- return self.buffer_w(space, space.BUF_SIMPLE)
-
- def writebuf_w(self, space):
- w_impl = space.lookup(self, '__buffer__')
- if w_impl is not None:
- w_result = space.get_and_call_function(w_impl, self)
- if space.isinstance_w(w_result, space.w_memoryview):
- return w_result.writebuf_w(space)
- return self.buffer_w(space, space.BUF_WRITABLE)
-
- def charbuf_w(self, space):
- w_impl = space.lookup(self, '__buffer__')
- if w_impl is not None:
- w_result = space.get_and_call_function(w_impl, self)
- if space.isinstance_w(w_result, space.w_memoryview):
- return w_result.charbuf_w(space)
- return self.buffer_w(space, space.BUF_SIMPLE).as_str()
-
def bytes_w(self, space):
self._typed_unwrap_error(space, "bytes")
@@ -1369,31 +1345,33 @@
return w_obj.buffer_w(self, flags)
except TypeError:
raise oefmt(self.w_TypeError,
- "'%T' does not have the buffer interface", w_obj)
+ "'%T' does not support the buffer interface", w_obj)
def readbuf_w(self, w_obj):
# Old buffer interface, returns a readonly buffer
(PyObject_AsReadBuffer)
try:
- return w_obj.readbuf_w(self)
+ return w_obj.buffer_w(self, self.BUF_SIMPLE)
except TypeError:
raise oefmt(self.w_TypeError,
- "expected a readable buffer object")
+ "expected an object with a buffer interface")
def writebuf_w(self, w_obj):
# Old buffer interface, returns a writeable buffer
(PyObject_AsWriteBuffer)
try:
- return w_obj.writebuf_w(self)
+ return w_obj.buffer_w(self, self.BUF_WRITABLE)
except TypeError:
raise oefmt(self.w_TypeError,
- "expected a writeable buffer object")
+ "expected an object with a writable buffer interface")
def charbuf_w(self, w_obj):
# Old buffer interface, returns a character buffer
(PyObject_AsCharBuffer)
try:
- return w_obj.charbuf_w(self)
+ buf = w_obj.buffer_w(self, self.BUF_SIMPLE)
except TypeError:
raise oefmt(self.w_TypeError,
- "expected a character buffer object")
+ "expected an object with a buffer interface")
+ else:
+ return buf.as_str()
def _getarg_error(self, expected, w_obj):
if self.is_none(w_obj):
@@ -1410,15 +1388,11 @@
code = 's*'
if code == 's*':
if self.isinstance_w(w_obj, self.w_str):
- return w_obj.readbuf_w(self)
+ return StringBuffer(w_obj.bytes_w(self))
if self.isinstance_w(w_obj, self.w_unicode):
return StringBuffer(w_obj.identifier_w(self))
try:
- return w_obj.buffer_w(self, 0)
- except TypeError:
- pass
- try:
- return w_obj.readbuf_w(self)
+ return w_obj.buffer_w(self, self.BUF_SIMPLE)
except TypeError:
self._getarg_error("bytes or buffer", w_obj)
elif code == 's#':
@@ -1427,7 +1401,7 @@
if self.isinstance_w(w_obj, self.w_unicode):
return w_obj.identifier_w(self)
try:
- return w_obj.readbuf_w(self).as_str()
+ return w_obj.buffer_w(self, self.BUF_SIMPLE).as_str()
except TypeError:
self._getarg_error("bytes or read-only buffer", w_obj)
elif code == 'w*':
@@ -1435,13 +1409,15 @@
try:
return w_obj.buffer_w(self, self.BUF_WRITABLE)
except OperationError:
- self._getarg_error("read-write buffer", w_obj)
+ pass
except TypeError:
pass
+ self._getarg_error("read-write buffer", w_obj)
+ elif code == 'y*':
try:
- return w_obj.writebuf_w(self)
+ return w_obj.buffer_w(self, self.BUF_SIMPLE)
except TypeError:
- self._getarg_error("read-write buffer", w_obj)
+ self._getarg_error("bytes or buffer", w_obj)
else:
assert False
@@ -1463,28 +1439,11 @@
try:
buf = w_obj.buffer_w(self, 0)
except TypeError:
- pass
- else:
- return buf.as_str()
- try:
- buf = w_obj.readbuf_w(self)
- except TypeError:
raise oefmt(self.w_TypeError,
"'%T' does not support the buffer interface", w_obj)
else:
return buf.as_str()
- def bufferstr_or_u_w(self, w_obj):
- """Returns an interp-level str, directly if possible.
-
- Accepts unicode or any type supporting the buffer
- interface. Unicode objects will be encoded to the default
- encoding (UTF-8)
- """
- if self.isinstance_w(w_obj, self.w_unicode):
- return w_obj.identifier_w(self)
- return self.bufferstr_w(w_obj)
-
def str_or_None_w(self, w_obj):
if self.is_w(w_obj, self.w_None):
return None
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -129,9 +129,6 @@
def visit_bufferstr(self, el, app_sig):
self.checked_space_method(el, app_sig)
- def visit_bufferstr_or_u(self, el, app_sig):
- self.checked_space_method(el, app_sig)
-
def visit_str_or_None(self, el, app_sig):
self.checked_space_method(el, app_sig)
@@ -251,9 +248,6 @@
def visit_bufferstr(self, typ):
self.run_args.append("space.bufferstr_w(%s)" % (self.scopenext(),))
- def visit_bufferstr_or_u(self, typ):
- self.run_args.append("space.bufferstr_or_u_w(%s)" %
(self.scopenext(),))
-
def visit_str_or_None(self, typ):
self.run_args.append("space.str_or_None_w(%s)" % (self.scopenext(),))
@@ -397,9 +391,6 @@
def visit_bufferstr(self, typ):
self.unwrap.append("space.bufferstr_w(%s)" % (self.nextarg(),))
- def visit_bufferstr_or_u(self, typ):
- self.unwrap.append("space.bufferstr_or_u_w(%s)" % (self.nextarg(),))
-
def visit_str_or_None(self, typ):
self.unwrap.append("space.str_or_None_w(%s)" % (self.nextarg(),))
diff --git a/pypy/module/_codecs/interp_codecs.py
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -769,9 +769,9 @@
return -1
return space.int_w(w_code)
-@unwrap_spec(string='bufferstr_or_u', errors='str_or_None',
- w_final=WrappedDefault(False))
-def unicode_escape_decode(space, string, errors="strict", w_final=None):
+@unwrap_spec(errors='str_or_None', w_final=WrappedDefault(False))
+def unicode_escape_decode(space, w_string, errors="strict", w_final=None):
+ string = space.getarg_w('s*', w_string).as_str()
if errors is None:
errors = 'strict'
final = space.is_true(w_final)
@@ -789,9 +789,9 @@
# ____________________________________________________________
# Raw Unicode escape (accepts bytes or str)
-@unwrap_spec(string='bufferstr_or_u', errors='str_or_None',
- w_final=WrappedDefault(False))
-def raw_unicode_escape_decode(space, string, errors="strict", w_final=None):
+@unwrap_spec(errors='str_or_None', w_final=WrappedDefault(False))
+def raw_unicode_escape_decode(space, w_string, errors="strict", w_final=None):
+ string = space.getarg_w('s*', w_string).as_str()
if errors is None:
errors = 'strict'
final = space.is_true(w_final)
@@ -828,14 +828,16 @@
# support for the "string escape" translation
# This is a bytes-to bytes transformation
-@unwrap_spec(data="bufferstr", errors='str_or_None')
-def escape_encode(space, data, errors='strict'):
+@unwrap_spec(errors='str_or_None')
+def escape_encode(space, w_data, errors='strict'):
+ data = space.bytes_w(w_data)
from pypy.objspace.std.bytesobject import string_escape_encode
result = string_escape_encode(data, False)
return space.newtuple([space.wrapbytes(result), space.wrap(len(data))])
-@unwrap_spec(data='bufferstr_or_u', errors='str_or_None')
-def escape_decode(space, data, errors='strict'):
+@unwrap_spec(errors='str_or_None')
+def escape_decode(space, w_data, errors='strict'):
+ data = space.getarg_w('s#', w_data)
from pypy.interpreter.pyparser.parsestring import PyString_DecodeEscape
result = PyString_DecodeEscape(space, data, errors, None)
return space.newtuple([space.wrapbytes(result), space.wrap(len(data))])
diff --git a/pypy/module/_io/interp_bufferedio.py
b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -710,7 +710,7 @@
def write_w(self, space, w_data):
self._check_init(space)
self._check_closed(space, "write to closed file")
- data = space.bufferstr_w(w_data)
+ data = space.getarg_w('y*', w_data).as_str()
size = len(data)
with self.lock:
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -340,7 +340,7 @@
def write_w(self, space, w_data):
self._check_closed(space)
self._check_writable(space)
- data = space.bufferstr_w(w_data)
+ data = space.getarg_w('y*', w_data).as_str()
try:
n = os.write(self.fd, data)
diff --git a/pypy/module/_io/test/test_bytesio.py
b/pypy/module/_io/test/test_bytesio.py
--- a/pypy/module/_io/test/test_bytesio.py
+++ b/pypy/module/_io/test/test_bytesio.py
@@ -44,7 +44,7 @@
assert f.write(b"") == 0
assert f.write(b"hello") == 5
exc = raises(TypeError, f.write, u"lo")
- assert str(exc.value) == "'str' does not have the buffer interface"
+ assert str(exc.value) == "'str' does not support the buffer interface"
import gc; gc.collect()
assert f.getvalue() == b"hello"
f.close()
diff --git a/pypy/module/_rawffi/interp_rawffi.py
b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -363,12 +363,6 @@
def buffer_w(self, space, flags):
return RawFFIBuffer(self)
- def readbuf_w(self, space):
- return RawFFIBuffer(self)
-
- def writebuf_w(self, space):
- return RawFFIBuffer(self)
-
def getrawsize(self):
raise NotImplementedError("abstract base class")
diff --git a/pypy/module/array/interp_array.py
b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -141,12 +141,6 @@
def buffer_w(self, space, flags):
return ArrayBuffer(self, False)
- def readbuf_w(self, space):
- return ArrayBuffer(self, True)
-
- def writebuf_w(self, space):
- return ArrayBuffer(self, False)
-
def descr_append(self, space, w_x):
""" append(x)
diff --git a/pypy/module/marshal/interp_marshal.py
b/pypy/module/marshal/interp_marshal.py
--- a/pypy/module/marshal/interp_marshal.py
+++ b/pypy/module/marshal/interp_marshal.py
@@ -466,9 +466,9 @@
# Unmarshaller with inlined buffer string
def __init__(self, space, w_str):
Unmarshaller.__init__(self, space, None)
- self.bufstr = space.getarg_w('s#', w_str)
+ self.buf = space.getarg_w('y*', w_str)
self.bufpos = 0
- self.limit = len(self.bufstr)
+ self.limit = self.buf.getlength()
def raise_eof(self):
space = self.space
@@ -481,14 +481,14 @@
if newpos > self.limit:
self.raise_eof()
self.bufpos = newpos
- return self.bufstr[pos : newpos]
+ return self.buf.getslice(pos, newpos, 1, newpos - pos)
def get1(self):
pos = self.bufpos
if pos >= self.limit:
self.raise_eof()
self.bufpos = pos + 1
- return self.bufstr[pos]
+ return self.buf.getitem(pos)
def get_int(self):
pos = self.bufpos
@@ -496,10 +496,10 @@
if newpos > self.limit:
self.raise_eof()
self.bufpos = newpos
- a = ord(self.bufstr[pos])
- b = ord(self.bufstr[pos+1])
- c = ord(self.bufstr[pos+2])
- d = ord(self.bufstr[pos+3])
+ a = ord(self.buf.getitem(pos))
+ b = ord(self.buf.getitem(pos+1))
+ c = ord(self.buf.getitem(pos+2))
+ d = ord(self.buf.getitem(pos+3))
if d & 0x80:
d -= 0x100
x = a | (b<<8) | (c<<16) | (d<<24)
@@ -511,10 +511,10 @@
if newpos > self.limit:
self.raise_eof()
self.bufpos = newpos
- a = ord(self.bufstr[pos])
- b = ord(self.bufstr[pos+1])
- c = ord(self.bufstr[pos+2])
- d = ord(self.bufstr[pos+3])
+ a = ord(self.buf.getitem(pos))
+ b = ord(self.buf.getitem(pos+1))
+ c = ord(self.buf.getitem(pos+2))
+ d = ord(self.buf.getitem(pos+3))
x = a | (b<<8) | (c<<16) | (d<<24)
if x >= 0:
return x
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -340,12 +340,6 @@
def buffer_w(self, space, flags):
return self.descr_ravel(space).buffer_w(space, flags)
- def readbuf_w(self, space):
- return self.descr_ravel(space).readbuf_w(space)
-
- def charbuf_w(self, space):
- return self.descr_ravel(space).charbuf_w(space)
-
def descr_byteswap(self, space):
return self.get_dtype(space).itemtype.byteswap(self)
diff --git a/pypy/module/micronumpy/ndarray.py
b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -621,15 +621,6 @@
def buffer_w(self, space, flags):
return self.implementation.get_buffer(space, True)
- def readbuf_w(self, space):
- return self.implementation.get_buffer(space, True)
-
- def writebuf_w(self, space):
- return self.implementation.get_buffer(space, False)
-
- def charbuf_w(self, space):
- return self.implementation.get_buffer(space, True).as_str()
-
def descr_get_data(self, space):
return space.newbuffer(self.implementation.get_buffer(space, False))
diff --git a/pypy/module/mmap/interp_mmap.py b/pypy/module/mmap/interp_mmap.py
--- a/pypy/module/mmap/interp_mmap.py
+++ b/pypy/module/mmap/interp_mmap.py
@@ -17,9 +17,9 @@
self.space = space
self.mmap = mmap_obj
- def readbuf_w(self, space):
+ def buffer_w(self, space, flags):
self.check_valid()
- return MMapBuffer(self.space, self.mmap, True)
+ return MMapBuffer(self.space, self.mmap, flags & space.BUF_WRITABLE)
def close(self):
self.mmap.close()
diff --git a/pypy/objspace/std/bytearrayobject.py
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -31,15 +31,6 @@
def buffer_w(self, space, flags):
return BytearrayBuffer(self.data, False)
- def readbuf_w(self, space):
- return BytearrayBuffer(self.data, True)
-
- def writebuf_w(self, space):
- return BytearrayBuffer(self.data, False)
-
- def charbuf_w(self, space):
- return ''.join(self.data)
-
def _new(self, value):
return W_BytearrayObject(_make_data(value))
@@ -59,7 +50,8 @@
raise oefmt(space.w_IndexError, "bytearray index out of range")
return space.wrap(ord(character))
- _val = charbuf_w
+ def _val(self, space):
+ return ''.join(self.data)
@staticmethod
def _op_val(space, w_other):
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
@@ -402,13 +402,6 @@
space.check_buf_flags(flags, True)
return StringBuffer(self._value)
- def readbuf_w(self, space):
- return StringBuffer(self._value)
-
- def writebuf_w(self, space):
- raise OperationError(space.w_TypeError, space.wrap(
- "Cannot use string as modifiable buffer"))
-
def listview_int(self):
return _create_list_from_bytes(self._value)
@@ -440,7 +433,7 @@
except OperationError, e:
if not e.match(space, space.w_TypeError):
raise
- return space.charbuf_w(w_other)
+ return space.buffer_w(w_other, space.BUF_SIMPLE).as_str()
def _chr(self, char):
assert len(char) == 1
diff --git a/pypy/objspace/std/strbufobject.py
b/pypy/objspace/std/strbufobject.py
--- a/pypy/objspace/std/strbufobject.py
+++ b/pypy/objspace/std/strbufobject.py
@@ -39,9 +39,6 @@
def buffer_w(self, space, flags):
return StringBuffer(self.force())
- def readbuf_w(self, space):
- return StringBuffer(self.force())
-
def descr_len(self, space):
return space.wrap(self.length)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit