[pypy-svn] r79116 - in pypy/branch/fast-forward/pypy: module/_winreg module/_winreg/test rlib

afa at codespeak.net afa at codespeak.net
Mon Nov 15 18:18:22 CET 2010


Author: afa
Date: Mon Nov 15 18:18:21 2010
New Revision: 79116

Modified:
   pypy/branch/fast-forward/pypy/module/_winreg/__init__.py
   pypy/branch/fast-forward/pypy/module/_winreg/interp_winreg.py
   pypy/branch/fast-forward/pypy/module/_winreg/test/test_winreg.py
   pypy/branch/fast-forward/pypy/rlib/rwinreg.py
Log:
add CreateKeyEx; this fixes the last test in 2.7's test_winreg.py


Modified: pypy/branch/fast-forward/pypy/module/_winreg/__init__.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_winreg/__init__.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_winreg/__init__.py	Mon Nov 15 18:18:21 2010
@@ -49,6 +49,7 @@
         'QueryValue'     : 'interp_winreg.QueryValue',
         'QueryValueEx'   : 'interp_winreg.QueryValueEx',
         'CreateKey'      : 'interp_winreg.CreateKey',
+        'CreateKeyEx'    : 'interp_winreg.CreateKeyEx',
         'DeleteKey'      : 'interp_winreg.DeleteKey',
         'DeleteValue'    : 'interp_winreg.DeleteValue',
         'OpenKey'        : 'interp_winreg.OpenKey',

Modified: pypy/branch/fast-forward/pypy/module/_winreg/interp_winreg.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_winreg/interp_winreg.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_winreg/interp_winreg.py	Mon Nov 15 18:18:21 2010
@@ -486,6 +486,28 @@
         return space.wrap(W_HKEY(rethkey[0]))
 CreateKey.unwrap_spec = [ObjSpace, W_Root, str]
 
+def CreateKeyEx(space, w_hkey, subkey, res=0, sam=rwinreg.KEY_WRITE):
+    """key = CreateKey(key, sub_key) - Creates or opens the specified key.
+
+key is an already open key, or one of the predefined HKEY_* constants
+sub_key is a string that names the key this method opens or creates.
+ If key is one of the predefined keys, sub_key may be None. In that case,
+ the handle returned is the same key handle passed in to the function.
+
+If the key already exists, this function opens the existing key
+
+The return value is the handle of the opened key.
+If the function fails, an exception is raised."""
+    hkey = hkey_w(w_hkey, space)
+    with lltype.scoped_alloc(rwinreg.PHKEY.TO, 1) as rethkey:
+        ret = rwinreg.RegCreateKeyEx(hkey, subkey, res, None, 0,
+                                     sam, None, rethkey,
+                                     lltype.nullptr(rwin32.LPDWORD.TO))
+        if ret != 0:
+            raiseWindowsError(space, ret, 'CreateKeyEx')
+        return space.wrap(W_HKEY(rethkey[0]))
+CreateKeyEx.unwrap_spec = [ObjSpace, W_Root, str, int, rffi.r_uint]
+
 def DeleteKey(space, w_hkey, subkey):
     """DeleteKey(key, sub_key) - Deletes the specified key.
 

Modified: pypy/branch/fast-forward/pypy/module/_winreg/test/test_winreg.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_winreg/test/test_winreg.py	(original)
+++ pypy/branch/fast-forward/pypy/module/_winreg/test/test_winreg.py	Mon Nov 15 18:18:21 2010
@@ -81,6 +81,18 @@
         nkeys, nvalues, since_mod = QueryInfoKey(sub_key)
         assert nkeys == 0
 
+    def test_CreateKeyEx(self):
+        from _winreg import CreateKeyEx, QueryInfoKey
+        from _winreg import KEY_ALL_ACCESS, KEY_READ
+        key = CreateKeyEx(self.root_key, self.test_key_name, 0, KEY_ALL_ACCESS)
+        sub_key = CreateKeyEx(key, "sub_key", 0, KEY_READ)
+
+        nkeys, nvalues, since_mod = QueryInfoKey(key)
+        assert nkeys == 1
+
+        nkeys, nvalues, since_mod = QueryInfoKey(sub_key)
+        assert nkeys == 0
+
     def test_close(self):
         from _winreg import OpenKey, CloseKey, FlushKey, QueryInfoKey
         key = OpenKey(self.root_key, self.test_key_name)

Modified: pypy/branch/fast-forward/pypy/rlib/rwinreg.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rwinreg.py	(original)
+++ pypy/branch/fast-forward/pypy/rlib/rwinreg.py	Mon Nov 15 18:18:21 2010
@@ -74,6 +74,12 @@
     [HKEY, rffi.CCHARP, PHKEY],
     rffi.LONG)
 
+RegCreateKeyEx = external(
+    'RegCreateKeyExA',
+    [HKEY, rffi.CCHARP, rwin32.DWORD, rffi.CCHARP, rwin32.DWORD,
+     REGSAM, rffi.VOIDP, PHKEY, rwin32.LPDWORD],
+    rffi.LONG)
+
 RegDeleteValue = external(
     'RegDeleteValueA',
     [HKEY, rffi.CCHARP],



More information about the Pypy-commit mailing list