Author: Brian Kearns <[email protected]>
Branch:
Changeset: r60728:63ac31bd95de
Date: 2013-01-30 07:59 -0500
http://bitbucket.org/pypy/pypy/changeset/63ac31bd95de/
Log: more closely imitate cpython handling of file descriptors
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1482,9 +1482,10 @@
)
raise
w_fd = self.call_function(w_fileno)
- if not self.isinstance_w(w_fd, self.w_int):
+ if (not self.isinstance_w(w_fd, self.w_int) and
+ not self.isinstance_w(w_fd, self.w_long)):
raise OperationError(self.w_TypeError,
- self.wrap("fileno() must return an integer")
+ self.wrap("fileno() returned a non-integer")
)
fd = self.int_w(w_fd)
if fd < 0:
diff --git a/pypy/module/fcntl/test/test_fcntl.py
b/pypy/module/fcntl/test/test_fcntl.py
--- a/pypy/module/fcntl/test/test_fcntl.py
+++ b/pypy/module/fcntl/test/test_fcntl.py
@@ -22,13 +22,23 @@
import sys
import struct
+ class F:
+ def __init__(self, fn):
+ self.fn = fn
+ def fileno(self):
+ return self.fn
+
f = open(self.tmp + "b", "w+")
fcntl.fcntl(f, 1, 0)
fcntl.fcntl(f, 1)
+ fcntl.fcntl(F(long(f.fileno())), 1)
raises(TypeError, fcntl.fcntl, "foo")
raises(TypeError, fcntl.fcntl, f, "foo")
- raises((IOError, ValueError), fcntl.fcntl, -1, 1, 0)
+ raises(TypeError, fcntl.fcntl, F("foo"), 1)
+ raises(ValueError, fcntl.fcntl, -1, 1, 0)
+ raises(ValueError, fcntl.fcntl, F(-1), 1, 0)
+ raises(ValueError, fcntl.fcntl, F(long(-1)), 1, 0)
assert fcntl.fcntl(f, 1, 0) == 0
assert fcntl.fcntl(f, 2, "foo") == "foo"
assert fcntl.fcntl(f, 2, buffer("foo")) == "foo"
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit