Commits

Philip Jenvey committed cdd83d6

fix handling of EnvironmentError filenames

  • Participants
  • Parent commits 5ce8d09
  • Branches py3k

Comments (0)

Files changed (2)

File pypy/module/_io/test/test_fileio.py

+# encoding: utf-8
 from rpython.tool.udir import udir
 import os
 
             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')

File pypy/module/exceptions/interp_exceptions.py

     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,
             ))
     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'):