Skip to content
Open
Show file tree
Hide file tree
Changes from 21 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
54 changes: 52 additions & 2 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 @@ -300,7 +307,6 @@ This module offers the following functions:


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

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

Expand Down Expand Up @@ -329,6 +335,50 @@ This module offers the following functions:
.. versionchanged:: 3.3
See :ref:`above <exception-changed>`.

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

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

*key* is an already open key, or one of the predefined
:ref:`HKEY_* constants <hkey-constants>`.

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

*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>`.

*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.

The result is a new handle to the specified key.

If the function fails, :exc:`OSError` is raised.

.. audit-event:: winreg.OpenKey key,sub_key,access winreg.OpenKey

.. audit-event:: winreg.OpenKey/result key winreg.OpenKey

.. versionchanged:: 3.2
Allow the use of named arguments.

.. versionchanged:: 3.3
See :ref:`above <exception-changed>`.

.. versionchanged:: 3.14
Added *options* parameter.

.. deprecated-removed:: 3.14 3.16
*reserved* is deprecated and will be removed in the future.
Please use *options* instead.


.. function:: QueryInfoKey(key)

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.

22 changes: 22 additions & 0 deletions Lib/test/test_winreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,28 @@ 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)

with self.assertWarns(DeprecationWarning):
okeo = lambda key, sub_key: OpenKeyEx(key, sub_key,
reserved=REG_OPTION_VOLATILE)
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`.
95 changes: 68 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