[pypy-svn] r77099 - in pypy/branch/fast-forward/pypy: module/_multiprocessing module/_multiprocessing/test rlib

afa at codespeak.net afa at codespeak.net
Wed Sep 15 19:37:30 CEST 2010


Author: afa
Date: Wed Sep 15 19:37:29 2010
New Revision: 77099

Added:
   pypy/branch/fast-forward/pypy/module/_multiprocessing/   (props changed)
   pypy/branch/fast-forward/pypy/module/_multiprocessing/__init__.py   (contents, props changed)
   pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py   (contents, props changed)
   pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_win32.py   (contents, props changed)
   pypy/branch/fast-forward/pypy/module/_multiprocessing/test/   (props changed)
   pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_win32.py   (contents, props changed)
Modified:
   pypy/branch/fast-forward/pypy/rlib/rwin32.py
Log:
Add the beginning of a _multiprocessing module


Added: pypy/branch/fast-forward/pypy/module/_multiprocessing/__init__.py
==============================================================================
--- (empty file)
+++ pypy/branch/fast-forward/pypy/module/_multiprocessing/__init__.py	Wed Sep 15 19:37:29 2010
@@ -0,0 +1,14 @@
+from pypy.interpreter.mixedmodule import MixedModule
+import sys
+
+class Module(MixedModule):
+
+    interpleveldefs = {
+        'Connection'      : 'interp_connection.W_SocketConnection',
+    }
+
+    appleveldefs = {
+    }
+
+    if sys.platform == 'win32':
+        interpleveldefs['win32'] = 'interp_win32.win32_namespace(space)'

Added: pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py
==============================================================================
--- (empty file)
+++ pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py	Wed Sep 15 19:37:29 2010
@@ -0,0 +1,43 @@
+from pypy.interpreter.baseobjspace import Wrappable
+from pypy.interpreter.typedef import TypeDef, GetSetProperty
+
+INVALID_HANDLE_VALUE = -1
+READABLE = 1
+WRITABLE = 2
+
+
+class W_BaseConnection(Wrappable):
+    def __init__(self, handle, flags):
+        self.handle = handle
+        self.flags = flags
+
+    def descr_repr(self, space):
+        conn_type = ["read-only", "write-only", "read-write"][self.flags]
+
+        return space.wrap("<%s %s, handle %zd>" % (
+            conn_type, space.type(self).getname(space, '?'), self.handle))
+
+    def close(self):
+        if self.handle != INVALID_HANDLE_VALUE:
+            self.do_close()
+            self.handle = INVALID_HANDLE_VALUE
+
+    def __del__(self):
+        self.close()
+
+    def closed_get(space, self):
+        return space.w_bool(self.handle == INVALID_HANDLE_VALUE)
+    def readable_get(space, self):
+        return space.w_bool(self.flags & READABLE)
+    def writable_get(space, self):
+        return space.w_bool(self.flags & WRITABLE)
+
+class W_SocketConnection(W_BaseConnection):
+    pass
+
+W_SocketConnection.typedef = TypeDef(
+    'Connection',
+    closed = GetSetProperty(W_BaseConnection.closed_get),
+    readable = GetSetProperty(W_BaseConnection.readable_get),
+    writable = GetSetProperty(W_BaseConnection.writable_get),
+)

Added: pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_win32.py
==============================================================================
--- (empty file)
+++ pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_win32.py	Wed Sep 15 19:37:29 2010
@@ -0,0 +1,30 @@
+from pypy.interpreter import gateway
+from pypy.interpreter.function import StaticMethod
+from pypy.interpreter.error import wrap_windowserror
+from pypy.rlib import rwin32
+from pypy.rpython.lltypesystem import rffi
+
+def handle_w(space, w_handle):
+    return rffi.cast(rwin32.HANDLE, space.int_w(w_handle))
+
+def CloseHandle(space, w_handle):
+    handle = handle_w(space, w_handle)
+    if not rwin32.CloseHandle(handle):
+        raise wrap_windowserror(space, rwin32.lastWindowsError())
+
+def win32_namespace(space):
+    "NOT_RPYTHON"
+    w_win32 = space.call_function(space.w_type,
+                                  space.wrap("win32"),
+                                  space.newtuple([]),
+                                  space.newdict())
+    try:
+        for name in ['CloseHandle',
+                     ]:
+            function = globals()[name]
+            w_function = space.wrap(gateway.interp2app(function))
+            w_method = space.wrap(StaticMethod(w_function))
+            space.setattr(w_win32, space.wrap(name), w_method)
+    except Exception, e:
+        import pdb; pdb.set_trace()
+    return w_win32

Added: pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_win32.py
==============================================================================
--- (empty file)
+++ pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_win32.py	Wed Sep 15 19:37:29 2010
@@ -0,0 +1,13 @@
+import py
+import sys
+from pypy.conftest import gettestobjspace
+
+class AppTestWin32:
+    def setup_class(cls):
+        if sys.platform != "win32":
+            py.test.skip("win32 only")
+        cls.space = gettestobjspace(usemodules=('_multiprocessing',))
+
+    def test_CloseHandle(self):
+        import _multiprocessing
+        raises(WindowsError, _multiprocessing.win32.CloseHandle, -1)

Modified: pypy/branch/fast-forward/pypy/rlib/rwin32.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rwin32.py	(original)
+++ pypy/branch/fast-forward/pypy/rlib/rwin32.py	Wed Sep 15 19:37:29 2010
@@ -102,7 +102,7 @@
     FreeLibrary = winexternal('FreeLibrary', [rffi.VOIDP], BOOL)
 
     LocalFree = winexternal('LocalFree', [HLOCAL], DWORD)
-    CloseHandle = winexternal('CloseHandle', [HANDLE], lltype.Void)
+    CloseHandle = winexternal('CloseHandle', [HANDLE], BOOL)
 
     FormatMessage = winexternal(
         'FormatMessageA',



More information about the Pypy-commit mailing list