[pypy-svn] r74621 - in pypy/trunk/pypy/module/posix: . test

afa at codespeak.net afa at codespeak.net
Fri May 21 13:17:23 CEST 2010


Author: afa
Date: Fri May 21 13:17:22 2010
New Revision: 74621

Modified:
   pypy/trunk/pypy/module/posix/app_posix.py
   pypy/trunk/pypy/module/posix/test/test_posix2.py
Log:
issue540 resolved: copy file.fdopen at import time, because setuptools
replaces __builtins__.file with its own function.


Modified: pypy/trunk/pypy/module/posix/app_posix.py
==============================================================================
--- pypy/trunk/pypy/module/posix/app_posix.py	(original)
+++ pypy/trunk/pypy/module/posix/app_posix.py	Fri May 21 13:17:22 2010
@@ -62,13 +62,16 @@
         if self.st_ctime is None:
             self.__dict__['st_ctime'] = self[9]
 
+# Capture file.fdopen at import time, as some code replaces
+# __builtins__.file with a custom function.
+_fdopen = file.fdopen
 
 def fdopen(fd, mode='r', buffering=-1):
     """fdopen(fd [, mode='r' [, buffering]]) -> file_object
 
     Return an open file object connected to a file descriptor."""
 
-    return file.fdopen(fd, mode, buffering)
+    return _fdopen(fd, mode, buffering)
 
 
 def tmpfile():

Modified: pypy/trunk/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/trunk/pypy/module/posix/test/test_posix2.py	(original)
+++ pypy/trunk/pypy/module/posix/test/test_posix2.py	Fri May 21 13:17:22 2010
@@ -249,6 +249,19 @@
         f = posix.fdopen(fd, "r")
         f.close()
 
+    def test_fdopen_hackedbuiltins(self):
+        "Same test, with __builtins__.file removed"
+        _file = __builtins__.file
+        __builtins__.file = None
+        try:
+            path = self.path
+            posix = self.posix
+            fd = posix.open(path, posix.O_RDONLY, 0777)
+            f = posix.fdopen(fd, "r")
+            f.close()
+        finally:
+            __builtins__.file = _file
+
     def test_getcwd(self):
         assert isinstance(self.posix.getcwd(), str)
         assert isinstance(self.posix.getcwdu(), unicode)



More information about the Pypy-commit mailing list