Author: Ronan Lamy <[email protected]>
Branch: follow_symlinks
Changeset: r83776:ad52aafa4b6e
Date: 2016-04-19 20:22 +0100
http://bitbucket.org/pypy/pypy/changeset/ad52aafa4b6e/
Log: (pjenvey, ronan) Query the buffer protocol in space.fsencode_w, not
space.bytes_w, and ensure that this is used everywhere in
interp_posix.py.
reverts 4b64950d0558898460fd9c7c126c085c1a6bdbfe
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -231,8 +231,7 @@
raise BufferInterfaceNotFound
def bytes_w(self, space):
- buffer = space.buffer_w(self, space.BUF_FULL_RO)
- return buffer.as_str()
+ self._typed_unwrap_error(space, "bytes")
def unicode_w(self, space):
self._typed_unwrap_error(space, "string")
@@ -1639,9 +1638,14 @@
return fsdecode(space, w_obj)
def fsencode_w(self, w_obj):
+ from rpython.rlib import rstring
if self.isinstance_w(w_obj, self.w_unicode):
w_obj = self.fsencode(w_obj)
- return self.bytes0_w(w_obj)
+ result = self.bufferstr_w(w_obj, self.BUF_FULL_RO)
+ if '\x00' in result:
+ raise oefmt(self.w_TypeError,
+ "argument must be a string without NUL characters")
+ return rstring.assert_str0(result)
def fsdecode_w(self, w_obj):
if self.isinstance_w(w_obj, self.w_bytes):
diff --git a/pypy/module/posix/interp_posix.py
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -64,7 +64,7 @@
self.w_obj = w_obj
def as_bytes(self):
- return self.space.bytes0_w(self.w_obj)
+ return self.space.fsencode_w(self.w_obj)
def as_unicode(self):
return self.space.fsdecode_w(self.w_obj)
@@ -83,7 +83,7 @@
fname = FileEncoder(space, w_fname)
return func(fname, *args)
else:
- fname = space.bytes0_w(w_fname)
+ fname = space.fsencode_w(w_fname)
return func(fname, *args)
return dispatch
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit