[pypy-commit] pypy default: call check_not_dir in fdopen

bdkearns noreply at buildbot.pypy.org
Wed Apr 9 20:49:31 CEST 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r70505:fcb0695ec986
Date: 2014-04-09 14:47 -0400
http://bitbucket.org/pypy/pypy/changeset/fcb0695ec986/

Log:	call check_not_dir in fdopen

diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -137,6 +137,7 @@
         self.check_mode_ok(mode)
         stream = streamio.fdopen_as_stream(fd, mode, buffering,
                                            signal_checker(self.space))
+        self.check_not_dir(fd)
         self.fdopenstream(stream, fd, mode)
 
     def direct_close(self):
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
@@ -305,6 +305,13 @@
         finally:
             __builtins__.file = _file
 
+    def test_fdopen_directory(self):
+        import errno
+        os = self.posix
+        fd = os.open('/', os.O_RDONLY)
+        exc = raises(IOError, os.fdopen, fd, 'r')
+        assert exc.value.errno == errno.EISDIR
+
     def test_getcwd(self):
         assert isinstance(self.posix.getcwd(), str)
         assert isinstance(self.posix.getcwdu(), unicode)
@@ -340,7 +347,6 @@
         else:
             assert (unicode, u) in typed_result
 
-
     def test_access(self):
         pdir = self.pdir + '/file1'
         posix = self.posix
@@ -351,7 +357,6 @@
         if sys.platform != "win32":
             assert not posix.access(pdir, posix.X_OK)
 
-
     def test_times(self):
         """
         posix.times() should return a five-tuple giving float-representations
@@ -1156,8 +1161,8 @@
             res = os.system(cmd)
             assert res == 0
 
+
 class AppTestPosixUnicode:
-
     def setup_class(cls):
         cls.space = space
         cls.w_posix = space.appexec([], GET_POSIX)
@@ -1198,6 +1203,7 @@
         except OSError:
             pass
 
+
 class AppTestUnicodeFilename:
     def setup_class(cls):
         ufilename = (unicode(udir.join('test_unicode_filename_')) +


More information about the pypy-commit mailing list