Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions Doc/library/winreg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ This module offers the following functions:
See :ref:`above <exception-changed>`.


.. function:: CreateKeyEx(key, sub_key, reserved=0, access=KEY_WRITE)
.. function:: CreateKeyEx(key, sub_key, reserved=0, access=KEY_WRITE, options=0, create_only=False)

Creates or opens the specified key, returning a
:ref:`handle object <handle-object>`.
Expand All @@ -101,6 +101,13 @@ This module offers the following functions:
security access for the key. Default is :const:`KEY_WRITE`. See
:ref:`Access Rights <access-rights>` for other allowed values.

*options* is an interger and can be zero or one of the predefined
:ref:`REG_OPTION_* constants <hkey-constants>`.

*create_only* is a boolean.
When set to True, a :exc:`FileExistsError` will be raised
if the key is already exists. Default is ``False``.

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.

Expand Down Expand Up @@ -299,8 +306,8 @@ This module offers the following functions:
.. audit-event:: winreg.LoadKey key,sub_key,file_name winreg.LoadKey


.. function:: OpenKey(key, sub_key, reserved=0, access=KEY_READ)
OpenKeyEx(key, sub_key, reserved=0, access=KEY_READ)
.. function:: OpenKey(key, sub_key, reserved=0, access=KEY_READ, options=0)
OpenKeyEx(key, sub_key, reserved=0, access=KEY_READ, options=0)

Opens the specified key, returning a :ref:`handle object <handle-object>`.

Expand All @@ -309,12 +316,20 @@ This module offers the following functions:

*sub_key* is a string that identifies the sub_key to open.

*reserved* is a reserved integer, and must be zero. The default is zero.
*reserved* is a reserved integer and should be zero.
If it is not zero, it will be treated as the options parameter.
You should use the *options* parameter directly instead,
this parameter is only included for compatibility reasons.
The default value is zero.

*access* is an integer that specifies an access mask that describes the desired
security access for the key. Default is :const:`KEY_READ`. See :ref:`Access
Rights <access-rights>` for other allowed values.

*options* specifies the option to apply when opening the key.
Can be zero or one of the predefined
:ref:`REG_OPTION_* constants <hkey-constants>`.

The result is a new handle to the specified key.

If the function fails, :exc:`OSError` is raised.
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(coro)
STRUCT_FOR_ID(count)
STRUCT_FOR_ID(covariant)
STRUCT_FOR_ID(create_only)
STRUCT_FOR_ID(cwd)
STRUCT_FOR_ID(data)
STRUCT_FOR_ID(database)
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Lib/test/test_winreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@ def test_registry_works_extended_functions(self):

self._delete_test_data(HKEY_CURRENT_USER)

def test_registry_works_with_options(self):
ckeo = lambda key, sub_key: CreateKeyEx(key, sub_key, 0, KEY_ALL_ACCESS,
options=REG_OPTION_VOLATILE)
self._write_test_data(HKEY_CURRENT_USER, CreateKey=ckeo)

okeo = lambda key, sub_key: OpenKeyEx(key, sub_key, REG_OPTION_VOLATILE, KEY_READ)
self._read_test_data(HKEY_CURRENT_USER, OpenKey=okeo)

self._delete_test_data(HKEY_CURRENT_USER)

def test_create_only(self):
CreateKeyEx(HKEY_CURRENT_USER, test_key_name)
with self.assertRaises(FileExistsError):
CreateKeyEx(HKEY_CURRENT_USER, test_key_name, create_only=True)
DeleteKey(HKEY_CURRENT_USER, test_key_name)

def test_named_arguments(self):
self._test_named_args(HKEY_CURRENT_USER, test_key_name)
# Use the regular DeleteKey to clean up
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add *options* and *create_only* parameters to :meth:`winreg.CreateKeyEx`.
Add *options* parameter to :meth:`winreg.OpenKeyEx`.
97 changes: 70 additions & 27 deletions PC/clinic/winreg.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading