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

afa at codespeak.net afa at codespeak.net
Mon Jan 26 11:38:55 CET 2009


Author: afa
Date: Mon Jan 26 11:38:55 2009
New Revision: 61350

Modified:
   pypy/trunk/pypy/module/posix/__init__.py
   pypy/trunk/pypy/module/posix/app_posix.py
   pypy/trunk/pypy/module/posix/test/test_posix2.py
Log:
win32: os.popen now works from a translated pypy-c.exe.

App-level tests don't work though, probably another msvcrt confusion.


Modified: pypy/trunk/pypy/module/posix/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/posix/__init__.py	(original)
+++ pypy/trunk/pypy/module/posix/__init__.py	Mon Jan 26 11:38:55 2009
@@ -18,6 +18,7 @@
     'stat_result': 'app_posix.stat_result',
     'fdopen'     : 'app_posix.fdopen',
     'tmpfile'    : 'app_posix.tmpfile',
+    'popen'      : 'app_posix.popen',
     }
     
     interpleveldefs = {
@@ -72,7 +73,6 @@
         interpleveldefs['readlink'] = 'interp_posix.readlink'
     if hasattr(os, 'fork'):
         interpleveldefs['fork'] = 'interp_posix.fork'
-        appleveldefs['popen'] = 'app_posix.popen'
     if hasattr(os, 'waitpid'):
         interpleveldefs['waitpid'] = 'interp_posix.waitpid'
     if hasattr(os, 'execv'):

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	Mon Jan 26 11:38:55 2009
@@ -142,26 +142,30 @@
 
 else:
     # Supply os.popen() based on subprocess
-    def popen(cmd, mode="r", buffering=None):
+    def popen(cmd, mode="r", bufsize=-1):
+        """popen(command [, mode='r' [, bufsize]]) -> pipe
+
+        Open a pipe to/from a command returning a file object."""
+
         if not isinstance(cmd, str):
             raise TypeError("invalid cmd type (%s, expected string)" %
                             (type(cmd),))
-        if mode not in ("r", "w"):
+
+        if not mode.startswith('r') and not mode.startswith('w'):
             raise ValueError("invalid mode %r" % (mode,))
-        if buffering is None:
-            buffering = 0
+
         import subprocess
-        if mode == "r":
+        if mode.startswith('r'):
             proc = subprocess.Popen(cmd,
                                     shell=True,
                                     stdout=subprocess.PIPE,
-                                    bufsize=buffering)
+                                    bufsize=bufsize)
             return _wrap_close(proc.stdout, proc)
         else:
             proc = subprocess.Popen(cmd,
                                     shell=True,
                                     stdin=subprocess.PIPE,
-                                    bufsize=buffering)
+                                    bufsize=bufsize)
             return _wrap_close(proc.stdin, proc)
 
     # A proxy for a file whose close waits for the process

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	Mon Jan 26 11:38:55 2009
@@ -8,8 +8,12 @@
 import sys
 import signal
 
-def setup_module(mod): 
-    mod.space = gettestobjspace(usemodules=['posix'])
+def setup_module(mod):
+    if os.name != 'nt':
+        mod.space = gettestobjspace(usemodules=['posix'])
+    else:
+        # On windows, os.popen uses the subprocess module
+        mod.space = gettestobjspace(usemodules=['posix', '_rawffi', 'thread'])
     mod.path = udir.join('posixtestfile.txt') 
     mod.path.write("this is a test")
     mod.path2 = udir.join('test_posix2-')



More information about the Pypy-commit mailing list