Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r88717:b3e1b9a536b3
Date: 2016-11-28 19:23 +0100
http://bitbucket.org/pypy/pypy/changeset/b3e1b9a536b3/
Log: Generate OSError with a filename2 from the posix module
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -561,7 +561,7 @@
@specialize.arg(3)
def wrap_oserror2(space, e, w_filename=None, exception_name='w_OSError',
- w_exception_class=None):
+ w_exception_class=None, w_filename2=None):
assert isinstance(e, OSError)
if _WINDOWS and isinstance(e, WindowsError):
@@ -581,8 +581,13 @@
else:
exc = w_exception_class
if w_filename is not None:
- w_error = space.call_function(exc, space.wrap(errno),
- space.wrap(msg), w_filename)
+ if w_filename2 is not None:
+ w_error = space.call_function(exc, space.wrap(errno),
+ space.wrap(msg), w_filename,
+ space.w_None, w_filename2)
+ else:
+ w_error = space.call_function(exc, space.wrap(errno),
+ space.wrap(msg), w_filename)
else:
w_error = space.call_function(exc, space.wrap(errno),
space.wrap(msg))
@@ -590,15 +595,17 @@
@specialize.arg(3)
def wrap_oserror(space, e, filename=None, exception_name='w_OSError',
- w_exception_class=None):
+ w_exception_class=None, filename2=None):
+ w_filename = None
+ w_filename2 = None
if filename is not None:
- return wrap_oserror2(space, e, space.wrap(filename),
- exception_name=exception_name,
- w_exception_class=w_exception_class)
- else:
- return wrap_oserror2(space, e, None,
- exception_name=exception_name,
- w_exception_class=w_exception_class)
+ w_filename = space.wrap(filename)
+ if filename2 is not None:
+ w_filename2 = space.wrap(filename2)
+ return wrap_oserror2(space, e, w_filename,
+ exception_name=exception_name,
+ w_exception_class=w_exception_class,
+ w_filename2=w_filename2)
def exception_from_saved_errno(space, w_type):
from rpython.rlib.rposix import get_saved_errno
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
@@ -1008,7 +1008,7 @@
else:
dispatch_filename_2(rposix.rename)(space, w_src, w_dst)
except OSError as e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror2(space, e, w_filename=w_src, w_filename2=w_dst)
@unwrap_spec(src_dir_fd=DirFD(rposix.HAVE_RENAMEAT),
dst_dir_fd=DirFD(rposix.HAVE_RENAMEAT))
@@ -1115,7 +1115,7 @@
rposix.kill(os.getpid(), signal.SIGABRT)
@unwrap_spec(
- src='fsencode', dst='fsencode',
+ src='fsencode', dst='fsencode', # <- simpler: link() is never on Windows
src_dir_fd=DirFD(rposix.HAVE_LINKAT), dst_dir_fd=DirFD(rposix.HAVE_LINKAT),
follow_symlinks=bool)
def link(
@@ -1144,7 +1144,7 @@
else:
rposix.link(src, dst)
except OSError as e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, filename=src, filename2=dst)
@unwrap_spec(dir_fd=DirFD(rposix.HAVE_SYMLINKAT))
@@ -1171,7 +1171,7 @@
else:
dispatch_filename_2(rposix.symlink)(space, w_src, w_dst)
except OSError as e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror2(space, e, w_filename=w_src, w_filename2=w_dst)
@unwrap_spec(
diff --git a/pypy/module/posix/test/test_posix2.py
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -1214,6 +1214,18 @@
self.posix.RTLD_GLOBAL
self.posix.RTLD_LOCAL
+ def test_error_message(self):
+ e = raises(OSError, self.posix.open, 'nonexistentfile1', 0)
+ assert str(e.value).endswith(": 'nonexistentfile1'")
+
+ e = raises(OSError, self.posix.link, 'nonexistentfile1', 'bok')
+ assert str(e.value).endswith(": 'nonexistentfile1' -> 'bok'")
+ e = raises(OSError, self.posix.rename, 'nonexistentfile1', 'bok')
+ assert str(e.value).endswith(": 'nonexistentfile1' -> 'bok'")
+
+ e = raises(OSError, self.posix.symlink, 'bok', '/nonexistentdir/boz')
+ assert str(e.value).endswith(": 'bok' -> '/nonexistentdir/boz'")
+
class AppTestEnvironment(object):
def setup_class(cls):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit