[pypy-commit] pypy py3k: fix handling of EnvironmentError filenames
pjenvey
noreply at buildbot.pypy.org
Tue May 13 20:29:39 CEST 2014
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r71491:cdd83d6f8d21
Date: 2014-05-13 10:56 -0700
http://bitbucket.org/pypy/pypy/changeset/cdd83d6f8d21/
Log: fix handling of EnvironmentError filenames
diff --git a/pypy/module/_io/test/test_fileio.py b/pypy/module/_io/test/test_fileio.py
--- a/pypy/module/_io/test/test_fileio.py
+++ b/pypy/module/_io/test/test_fileio.py
@@ -1,3 +1,4 @@
+# encoding: utf-8
from rpython.tool.udir import udir
import os
@@ -55,6 +56,14 @@
raises(IOError, _io.FileIO, fd, "rb")
os.close(fd)
+ def test_open_non_existent_unicode(self):
+ import _io
+ import os
+ path = os.path.join(self.tmpdir, '_pypy-日本')
+ exc = raises(IOError, _io.FileIO, path)
+ expected = "[Errno 2] No such file or directory: %r" % path
+ assert str(exc.value) == expected
+
def test_readline(self):
import _io
f = _io.FileIO(self.tmpfile, 'rb')
diff --git a/pypy/module/exceptions/interp_exceptions.py b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -389,14 +389,14 @@
def descr_str(self, space):
if (not space.is_w(self.w_errno, space.w_None) and
not space.is_w(self.w_strerror, space.w_None)):
- errno = space.str_w(space.str(self.w_errno))
- strerror = space.str_w(space.str(self.w_strerror))
+ errno = space.unicode_w(space.str(self.w_errno))
+ strerror = space.unicode_w(space.str(self.w_strerror))
if not space.is_w(self.w_filename, space.w_None):
- return space.wrap("[Errno %s] %s: %s" % (
+ return space.wrap(u"[Errno %s] %s: %s" % (
errno,
strerror,
- space.str_w(space.repr(self.w_filename))))
- return space.wrap("[Errno %s] %s" % (
+ space.unicode_w(space.repr(self.w_filename))))
+ return space.wrap(u"[Errno %s] %s" % (
errno,
strerror,
))
@@ -441,13 +441,15 @@
def descr_str(self, space):
if (not space.is_w(self.w_winerror, space.w_None) and
not space.is_w(self.w_strerror, space.w_None)):
+ winerror = space.int_w(self.w_winerror)
+ strerror = space.unicode_w(self.w_strerror)
if not space.is_w(self.w_filename, space.w_None):
- return space.wrap("[Error %d] %s: %s" % (
- space.int_w(self.w_winerror),
- space.str_w(self.w_strerror),
- space.str_w(self.w_filename)))
- return space.wrap("[Error %d] %s" % (space.int_w(self.w_winerror),
- space.str_w(self.w_strerror)))
+ return space.wrap(u"[Error %d] %s: %s" % (
+ winerror,
+ strerror,
+ space.unicode_w(self.w_filename)))
+ return space.wrap(u"[Error %d] %s" % (winerror,
+ strerror))
return W_BaseException.descr_str(self, space)
if hasattr(rwin32, 'build_winerror_to_errno'):
More information about the pypy-commit
mailing list