Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r88726:aa4ad227978a
Date: 2016-11-29 10:12 +0100
http://bitbucket.org/pypy/pypy/changeset/aa4ad227978a/
Log: Catch and wrap the RPython-level OSError
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
@@ -2219,13 +2219,20 @@
@unwrap_spec(fd=c_int)
def get_blocking(space, fd):
- return space.newbool(rposix.get_status_flags(fd) & rposix.O_NONBLOCK == 0)
+ try:
+ flags = rposix.get_status_flags(fd)
+ except OSError as e:
+ raise wrap_oserror(space, e)
+ return space.newbool(flags & rposix.O_NONBLOCK == 0)
@unwrap_spec(fd=c_int, blocking=int)
def set_blocking(space, fd, blocking):
- flags = rposix.get_status_flags(fd)
- if blocking:
- flags &= ~rposix.O_NONBLOCK
- else:
- flags |= rposix.O_NONBLOCK
- rposix.set_status_flags(fd, flags)
+ try:
+ flags = rposix.get_status_flags(fd)
+ if blocking:
+ flags &= ~rposix.O_NONBLOCK
+ else:
+ flags |= rposix.O_NONBLOCK
+ rposix.set_status_flags(fd, flags)
+ except OSError as e:
+ raise wrap_oserror(space, e)
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
@@ -1148,6 +1148,11 @@
assert posix.get_blocking(fd) is True
posix.close(fd)
+ def test_blocking_error(self):
+ posix = self.posix
+ raises(OSError, posix.get_blocking, 1234567)
+ raises(OSError, posix.set_blocking, 1234567, True)
+
def test_urandom(self):
os = self.posix
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit