[pypy-commit] pypy refactor-buffer-api: fix usage of bufferstr_w in _io
bdkearns
noreply at buildbot.pypy.org
Thu Apr 24 05:36:26 CEST 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch: refactor-buffer-api
Changeset: r70917:48ee80cfca6b
Date: 2014-04-23 23:20 -0400
http://bitbucket.org/pypy/pypy/changeset/48ee80cfca6b/
Log: fix usage of bufferstr_w in _io
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1416,7 +1416,20 @@
@specialize.arg(1)
def getarg_w(self, code, w_obj):
- if code == 'w*':
+ if code == 's*':
+ if self.isinstance_w(w_obj, self.w_str):
+ return w_obj.readbuf_w(self)
+ if self.isinstance_w(w_obj, self.w_unicode):
+ return self.str(w_obj).readbuf_w(self)
+ try:
+ return w_obj.buffer_w(self, 0)
+ except TypeError:
+ pass
+ try:
+ return w_obj.readbuf_w(self)
+ except TypeError:
+ self._getarg_error("string or buffer", w_obj)
+ elif code == 'w*':
try:
try:
return w_obj.buffer_w(self, self.BUF_WRITABLE)
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
@@ -701,7 +701,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('s*', w_data).as_str()
size = len(data)
with self.lock:
diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -50,10 +50,7 @@
def write_w(self, space, w_data):
self._check_closed(space)
- if space.isinstance_w(w_data, space.w_unicode):
- raise OperationError(space.w_TypeError, space.wrap(
- "bytes string of buffer expected"))
- buf = space.bufferstr_w(w_data)
+ buf = space.buffer_w(w_data, space.BUF_CONTIG_RO).as_str()
length = len(buf)
if length <= 0:
return space.wrap(0)
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
@@ -333,7 +333,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('s*', w_data).as_str()
try:
n = os.write(self.fd, data)
More information about the pypy-commit
mailing list