lib-registry 3.2.0__tar.gz → 3.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lib_registry-3.2.0 → lib_registry-3.3.0}/CHANGELOG.md +21 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/PKG-INFO +2 -2
- {lib_registry-3.2.0 → lib_registry-3.3.0}/docs/systemdesign/module_reference.md +2 -2
- {lib_registry-3.2.0 → lib_registry-3.3.0}/pyproject.toml +2 -2
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/__init__conf__.py +1 -1
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/_cli_helpers.py +2 -1
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/_winreg_setup.py +49 -39
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/registry.py +25 -5
- lib_registry-3.3.0/tests/test_remote.py +120 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/tests/test_walks.py +16 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/.gitignore +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/LICENSE +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/README.md +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/__init__.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/__main__.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/_helpers.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/cli.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/exceptions.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/py.typed +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/records.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/src/lib_registry/typed_click.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/tests/conftest.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/tests/test_cli.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/tests/test_metadata.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/tests/test_module_entry.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/tests/test_packaging.py +0 -0
- {lib_registry-3.2.0 → lib_registry-3.3.0}/tests/test_platform_markers.py +0 -0
|
@@ -5,6 +5,27 @@ the [Keep a Changelog](https://keepachangelog.com/) format.
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [3.3.0] - 2026-11-24
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- `fake_winreg>=1.11.0` (runtime, non-Windows); `uv.lock` refreshed.
|
|
13
|
+
- The exported lookup tables `main_key_hashed_by_name`, `hive_names_hashed_by_int` and
|
|
14
|
+
`reg_type_names_hashed_by_int` are now read-only `MappingProxyType` views, typed `Mapping`.
|
|
15
|
+
Every key parse in a process reads them, so a caller writing an entry changed how every later
|
|
16
|
+
key resolved. Reading, `in`, iteration, `.items()` and `dict(table)` work as before; item
|
|
17
|
+
assignment, `.update()`, `json.dumps(table)` and pickling no longer do (use `dict(table)`).
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- Remote registry access did not reach the remote computer. `Registry(computer_name="X")` (and the
|
|
22
|
+
CLI's `--computer X`, which builds it that way) connected every hive to the LOCAL computer, so
|
|
23
|
+
reads and writes silently went to the local registry. `Registry("HKLM", computer_name="X")`
|
|
24
|
+
connected that one hive to X and then refused every further operation with
|
|
25
|
+
`RegistryError: can not connect to different Machines in the same scope`. Every connection now
|
|
26
|
+
goes to the computer the `Registry` was created for, and `create_key`, `delete_key` and
|
|
27
|
+
`delete_key_ex` work through that computer's connection instead of the bare local hive constant.
|
|
28
|
+
|
|
8
29
|
## [3.2.0] - 2026-11-24
|
|
9
30
|
|
|
10
31
|
### Changed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: lib_registry
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.3.0
|
|
4
4
|
Summary: a more pythonic way to access the windows registry as winreg
|
|
5
5
|
Project-URL: Homepage, https://github.com/bitranox/lib_registry
|
|
6
6
|
Project-URL: Repository, https://github.com/bitranox/lib_registry.git
|
|
@@ -25,7 +25,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
25
25
|
Classifier: Topic :: System :: Systems Administration
|
|
26
26
|
Classifier: Typing :: Typed
|
|
27
27
|
Requires-Python: >=3.10
|
|
28
|
-
Requires-Dist: fake-winreg>=1.
|
|
28
|
+
Requires-Dist: fake-winreg>=1.11.0; sys_platform != 'win32'
|
|
29
29
|
Requires-Dist: rich-click>=1.9.9
|
|
30
30
|
Requires-Dist: rtoml>=0.14.0
|
|
31
31
|
Provides-Extra: dev
|
|
@@ -140,8 +140,8 @@ compares like the tuple `winreg` returns.
|
|
|
140
140
|
* All `REG_*` type constants (12 types)
|
|
141
141
|
* All `KEY_*` access constants (12 constants including WOW64)
|
|
142
142
|
* `l_hive_names` — `frozenset` for O(1) hive name lookups
|
|
143
|
-
* Lookup
|
|
144
|
-
`reg_type_names_hashed_by_int`
|
|
143
|
+
* Lookup tables, read-only `MappingProxyType` views: `main_key_hashed_by_name`,
|
|
144
|
+
`hive_names_hashed_by_int`, `reg_type_names_hashed_by_int`
|
|
145
145
|
|
|
146
146
|
### CLI Commands
|
|
147
147
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "lib_registry"
|
|
3
|
-
version = "3.
|
|
3
|
+
version = "3.3.0"
|
|
4
4
|
description = "a more pythonic way to access the windows registry as winreg"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
7
7
|
dependencies = [
|
|
8
8
|
"rich-click>=1.9.9",
|
|
9
9
|
"rtoml>=0.14.0",
|
|
10
|
-
"fake_winreg>=1.
|
|
10
|
+
"fake_winreg>=1.11.0; sys_platform!='win32'",
|
|
11
11
|
]
|
|
12
12
|
license = { text = "MIT" }
|
|
13
13
|
authors = [{ name = "bitranox", email = "bitranox@gmail.com" }]
|
|
@@ -24,7 +24,7 @@ name = "lib_registry"
|
|
|
24
24
|
#: Human-readable summary shown in CLI help output.
|
|
25
25
|
title = "a more pythonic way to access the windows registry as winreg"
|
|
26
26
|
#: Current release version pulled from ``pyproject.toml`` by automation.
|
|
27
|
-
version = "3.
|
|
27
|
+
version = "3.3.0"
|
|
28
28
|
#: Repository homepage presented to users.
|
|
29
29
|
homepage = "https://github.com/bitranox/lib_registry"
|
|
30
30
|
#: Author attribution surfaced in CLI output.
|
|
@@ -13,6 +13,7 @@ import textwrap
|
|
|
13
13
|
from collections.abc import Iterable, Iterator, Mapping
|
|
14
14
|
from dataclasses import dataclass
|
|
15
15
|
from enum import Enum
|
|
16
|
+
from types import MappingProxyType
|
|
16
17
|
from typing import NamedTuple
|
|
17
18
|
|
|
18
19
|
import rich_click as click
|
|
@@ -25,7 +26,7 @@ from .records import RegValue
|
|
|
25
26
|
from .registry import Registry
|
|
26
27
|
|
|
27
28
|
_TYPE_NAMES = list(reg_type_names_hashed_by_int.values())
|
|
28
|
-
_TYPE_NAME_TO_INT = {v: k for k, v in reg_type_names_hashed_by_int.items()}
|
|
29
|
+
_TYPE_NAME_TO_INT: Mapping[str, int] = MappingProxyType({v: k for k, v in reg_type_names_hashed_by_int.items()})
|
|
29
30
|
#: Largest value a REG_DWORD (unsigned 32-bit integer) can hold.
|
|
30
31
|
_REG_DWORD_MAX = 0xFFFFFFFF
|
|
31
32
|
|
|
@@ -5,6 +5,8 @@ imported. All other modules import ``winreg`` from here.
|
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
import sys
|
|
8
|
+
from collections.abc import Mapping
|
|
9
|
+
from types import MappingProxyType
|
|
8
10
|
|
|
9
11
|
is_platform_windows = sys.platform == "win32"
|
|
10
12
|
|
|
@@ -30,22 +32,26 @@ RegData = None | bytes | int | str | list[str]
|
|
|
30
32
|
# Constants
|
|
31
33
|
# ---------------------------------------------------------------------------
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
# The lookup tables are read-only views: every key parse in the process reads them, so one caller
|
|
36
|
+
# writing an entry would change how every later key is resolved.
|
|
37
|
+
main_key_hashed_by_name: Mapping[str, int] = MappingProxyType(
|
|
38
|
+
{
|
|
39
|
+
"hkey_classes_root": winreg.HKEY_CLASSES_ROOT,
|
|
40
|
+
"hkcr": winreg.HKEY_CLASSES_ROOT,
|
|
41
|
+
"hkey_current_config": winreg.HKEY_CURRENT_CONFIG,
|
|
42
|
+
"hkcc": winreg.HKEY_CURRENT_CONFIG,
|
|
43
|
+
"hkey_current_user": winreg.HKEY_CURRENT_USER,
|
|
44
|
+
"hkcu": winreg.HKEY_CURRENT_USER,
|
|
45
|
+
"hkey_dyn_data": winreg.HKEY_DYN_DATA,
|
|
46
|
+
"hkdd": winreg.HKEY_DYN_DATA,
|
|
47
|
+
"hkey_local_machine": winreg.HKEY_LOCAL_MACHINE,
|
|
48
|
+
"hklm": winreg.HKEY_LOCAL_MACHINE,
|
|
49
|
+
"hkey_performance_data": winreg.HKEY_PERFORMANCE_DATA,
|
|
50
|
+
"hkpd": winreg.HKEY_PERFORMANCE_DATA,
|
|
51
|
+
"hkey_users": winreg.HKEY_USERS,
|
|
52
|
+
"hku": winreg.HKEY_USERS,
|
|
53
|
+
}
|
|
54
|
+
)
|
|
49
55
|
|
|
50
56
|
l_hive_names: frozenset[str] = frozenset(
|
|
51
57
|
{
|
|
@@ -66,30 +72,34 @@ l_hive_names: frozenset[str] = frozenset(
|
|
|
66
72
|
}
|
|
67
73
|
)
|
|
68
74
|
|
|
69
|
-
hive_names_hashed_by_int:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
hive_names_hashed_by_int: Mapping[int, str] = MappingProxyType(
|
|
76
|
+
{
|
|
77
|
+
winreg.HKEY_CLASSES_ROOT: "HKEY_CLASSES_ROOT",
|
|
78
|
+
winreg.HKEY_CURRENT_CONFIG: "HKEY_CURRENT_CONFIG",
|
|
79
|
+
winreg.HKEY_CURRENT_USER: "HKEY_CURRENT_USER",
|
|
80
|
+
winreg.HKEY_DYN_DATA: "HKEY_DYN_DATA",
|
|
81
|
+
winreg.HKEY_LOCAL_MACHINE: "HKEY_LOCAL_MACHINE",
|
|
82
|
+
winreg.HKEY_PERFORMANCE_DATA: "HKEY_PERFORMANCE_DATA",
|
|
83
|
+
winreg.HKEY_USERS: "HKEY_USERS",
|
|
84
|
+
}
|
|
85
|
+
)
|
|
78
86
|
|
|
79
|
-
reg_type_names_hashed_by_int:
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
reg_type_names_hashed_by_int: Mapping[int, str] = MappingProxyType(
|
|
88
|
+
{
|
|
89
|
+
winreg.REG_BINARY: "REG_BINARY",
|
|
90
|
+
winreg.REG_DWORD: "REG_DWORD",
|
|
91
|
+
winreg.REG_DWORD_BIG_ENDIAN: "REG_DWORD_BIG_ENDIAN",
|
|
92
|
+
winreg.REG_EXPAND_SZ: "REG_EXPAND_SZ",
|
|
93
|
+
winreg.REG_LINK: "REG_LINK",
|
|
94
|
+
winreg.REG_MULTI_SZ: "REG_MULTI_SZ",
|
|
95
|
+
winreg.REG_NONE: "REG_NONE",
|
|
96
|
+
winreg.REG_QWORD: "REG_QWORD",
|
|
97
|
+
winreg.REG_RESOURCE_LIST: "REG_RESOURCE_LIST",
|
|
98
|
+
winreg.REG_FULL_RESOURCE_DESCRIPTOR: "REG_FULL_RESOURCE_DESCRIPTOR",
|
|
99
|
+
winreg.REG_RESOURCE_REQUIREMENTS_LIST: "REG_RESOURCE_REQUIREMENTS_LIST",
|
|
100
|
+
winreg.REG_SZ: "REG_SZ",
|
|
101
|
+
}
|
|
102
|
+
)
|
|
93
103
|
|
|
94
104
|
# ---------------------------------------------------------------------------
|
|
95
105
|
# Windows error codes used in exception mapping
|
|
@@ -9,6 +9,7 @@ See Also:
|
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
11
|
import contextlib
|
|
12
|
+
import enum
|
|
12
13
|
import pathlib
|
|
13
14
|
from collections.abc import Iterator
|
|
14
15
|
from types import TracebackType
|
|
@@ -73,6 +74,15 @@ from .records import KeyInfo, RegValue, TypedValue
|
|
|
73
74
|
# ---------------------------------------------------------------------------
|
|
74
75
|
|
|
75
76
|
|
|
77
|
+
class _ThisRegistrysComputer(enum.Enum):
|
|
78
|
+
"""Default of ``_reg_connect``'s ``computer_name``: the computer this Registry is bound to.
|
|
79
|
+
|
|
80
|
+
A sentinel rather than ``None``, because ``None`` already means the local computer.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
SAME = enum.auto()
|
|
84
|
+
|
|
85
|
+
|
|
76
86
|
class Registry:
|
|
77
87
|
"""Pythonic interface for Windows registry access.
|
|
78
88
|
|
|
@@ -167,7 +177,11 @@ class Registry:
|
|
|
167
177
|
# Connection management
|
|
168
178
|
# ------------------------------------------------------------------
|
|
169
179
|
|
|
170
|
-
def _reg_connect(
|
|
180
|
+
def _reg_connect(
|
|
181
|
+
self,
|
|
182
|
+
key: str | int,
|
|
183
|
+
computer_name: str | _ThisRegistrysComputer | None = _ThisRegistrysComputer.SAME,
|
|
184
|
+
) -> winreg.HKEYType:
|
|
171
185
|
r"""Establish a connection to a predefined registry hive.
|
|
172
186
|
|
|
173
187
|
Connections are cached and reused. Users typically do not call this
|
|
@@ -175,7 +189,8 @@ class Registry:
|
|
|
175
189
|
|
|
176
190
|
Args:
|
|
177
191
|
key: Predefined HKEY_* constant or hive name string.
|
|
178
|
-
computer_name: Remote computer name or None for local.
|
|
192
|
+
computer_name: Remote computer name or None for local. Omitted, the
|
|
193
|
+
computer this Registry was created for (``self.computer_name``).
|
|
179
194
|
|
|
180
195
|
Returns:
|
|
181
196
|
Handle to the opened hive.
|
|
@@ -228,6 +243,8 @@ class Registry:
|
|
|
228
243
|
...
|
|
229
244
|
lib_registry.exceptions.RegistryNetworkConnectionError: ...
|
|
230
245
|
"""
|
|
246
|
+
if computer_name is _ThisRegistrysComputer.SAME:
|
|
247
|
+
computer_name = self.computer_name
|
|
231
248
|
try:
|
|
232
249
|
if self._is_computer_name_set and computer_name != self.computer_name:
|
|
233
250
|
raise RegistryError("can not connect to different Machines in the same scope")
|
|
@@ -239,6 +256,9 @@ class Registry:
|
|
|
239
256
|
|
|
240
257
|
hive_handle: winreg.HKEYType = winreg.ConnectRegistry(computer_name, hive_key)
|
|
241
258
|
self.reg_hive_connections[hive_key] = hive_handle
|
|
259
|
+
# The first connection binds the scope to its computer, so every later call that
|
|
260
|
+
# omits computer_name reaches the same one.
|
|
261
|
+
self.computer_name = computer_name
|
|
242
262
|
self._is_computer_name_set = True
|
|
243
263
|
return hive_handle
|
|
244
264
|
|
|
@@ -366,7 +386,7 @@ class Registry:
|
|
|
366
386
|
key_str = get_key_as_string(hive_key, hive_sub_key)
|
|
367
387
|
raise RegistryKeyCreateError(f'can not create key, the parent key to "{key_str}" does not exist')
|
|
368
388
|
|
|
369
|
-
new_key_handle: winreg.HKEYType = winreg.CreateKey(hive_key, hive_sub_key)
|
|
389
|
+
new_key_handle: winreg.HKEYType = winreg.CreateKey(self._reg_connect(hive_key), hive_sub_key)
|
|
370
390
|
self.reg_key_handles[(hive_key, hive_sub_key, winreg.KEY_ALL_ACCESS)] = new_key_handle
|
|
371
391
|
return new_key_handle
|
|
372
392
|
|
|
@@ -441,7 +461,7 @@ class Registry:
|
|
|
441
461
|
self.reg_key_handles[(hive_key, hive_sub_key, winreg.KEY_ALL_ACCESS)].Close()
|
|
442
462
|
|
|
443
463
|
try:
|
|
444
|
-
winreg.DeleteKey(hive_key, hive_sub_key)
|
|
464
|
+
winreg.DeleteKey(self._reg_connect(hive_key), hive_sub_key)
|
|
445
465
|
except OSError as e:
|
|
446
466
|
# WinError 1018: key marked for deletion
|
|
447
467
|
if hasattr(e, "winerror") and e.winerror == _WINERROR_KEY_MARKED_FOR_DELETION: # type: ignore[attr-defined]
|
|
@@ -1059,7 +1079,7 @@ class Registry:
|
|
|
1059
1079
|
"""
|
|
1060
1080
|
hive_key, hive_sub_key = resolve_key(key, sub_key)
|
|
1061
1081
|
try:
|
|
1062
|
-
winreg.DeleteKeyEx(hive_key, hive_sub_key, access, 0) # type: ignore[attr-defined]
|
|
1082
|
+
winreg.DeleteKeyEx(self._reg_connect(hive_key), hive_sub_key, access, 0) # type: ignore[attr-defined]
|
|
1063
1083
|
except FileNotFoundError:
|
|
1064
1084
|
key_str = get_key_as_string(key, sub_key)
|
|
1065
1085
|
raise RegistryKeyDeleteError(f'can not delete key "{key_str}"') from None
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""A Registry bound to a remote computer sends every operation through that computer's connection.
|
|
2
|
+
|
|
3
|
+
fake_winreg cannot reach another machine: its ConnectRegistry raises for every computer name. These
|
|
4
|
+
tests replace ``ConnectRegistry`` - the one call that leaves the machine - with a recorder that
|
|
5
|
+
answers with the local hive, and record which handle the key-level calls receive. Everything below
|
|
6
|
+
that edge is the real code and the real fake registry.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import uuid
|
|
10
|
+
from collections.abc import Callable, Iterator
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
from click.testing import CliRunner
|
|
15
|
+
|
|
16
|
+
import lib_registry.registry as registry_module
|
|
17
|
+
from lib_registry import Registry, RegistryError
|
|
18
|
+
from lib_registry import cli as cli_mod
|
|
19
|
+
|
|
20
|
+
_REMOTE = "remotehost"
|
|
21
|
+
_CURRENT_VERSION = "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class _Wire:
|
|
26
|
+
"""What crossed the edge: the computer names asked for and the handles the key calls got."""
|
|
27
|
+
|
|
28
|
+
computer_names: list[str | None] = field(default_factory=list[str | None])
|
|
29
|
+
connections: list[object] = field(default_factory=list[object])
|
|
30
|
+
key_call_bases: list[object] = field(default_factory=list[object])
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.fixture
|
|
34
|
+
def wire(monkeypatch: pytest.MonkeyPatch) -> _Wire:
|
|
35
|
+
"""Record ConnectRegistry and the first argument of CreateKey/DeleteKey/DeleteKeyEx."""
|
|
36
|
+
recorded = _Wire()
|
|
37
|
+
winreg = registry_module.winreg
|
|
38
|
+
real_connect = winreg.ConnectRegistry
|
|
39
|
+
|
|
40
|
+
def connect(computer_name: str | None, hive: int) -> object:
|
|
41
|
+
recorded.computer_names.append(computer_name)
|
|
42
|
+
handle = real_connect(None, hive)
|
|
43
|
+
recorded.connections.append(handle)
|
|
44
|
+
return handle
|
|
45
|
+
|
|
46
|
+
def recording(real: Callable[..., object]) -> Callable[..., object]:
|
|
47
|
+
def call(base: object, *args: object) -> object:
|
|
48
|
+
recorded.key_call_bases.append(base)
|
|
49
|
+
return real(base, *args)
|
|
50
|
+
|
|
51
|
+
return call
|
|
52
|
+
|
|
53
|
+
monkeypatch.setattr(winreg, "ConnectRegistry", connect)
|
|
54
|
+
for name in ("CreateKey", "DeleteKey", "DeleteKeyEx"):
|
|
55
|
+
monkeypatch.setattr(winreg, name, recording(getattr(winreg, name)))
|
|
56
|
+
return recorded
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.fixture
|
|
60
|
+
def remote_key() -> Iterator[str]:
|
|
61
|
+
"""Name a key private to this test under HKCU and remove whatever the test left there."""
|
|
62
|
+
key = f"HKCU\\Software\\lib_registry_remote_test_{uuid.uuid4().hex}"
|
|
63
|
+
yield key
|
|
64
|
+
with Registry() as local:
|
|
65
|
+
local.delete_key(key, delete_subkeys=True, missing_ok=True)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@pytest.mark.os_agnostic
|
|
69
|
+
def test_a_registry_given_only_a_computer_name_reads_from_that_computer(wire: _Wire) -> None:
|
|
70
|
+
with Registry(computer_name=_REMOTE) as registry:
|
|
71
|
+
registry.get_value(_CURRENT_VERSION, "CurrentBuild")
|
|
72
|
+
|
|
73
|
+
assert wire.computer_names == [_REMOTE]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@pytest.mark.os_agnostic
|
|
77
|
+
def test_a_registry_given_a_hive_and_a_computer_name_reads_from_that_computer(wire: _Wire) -> None:
|
|
78
|
+
with Registry("HKLM", computer_name=_REMOTE) as registry:
|
|
79
|
+
registry.get_value(_CURRENT_VERSION, "CurrentBuild")
|
|
80
|
+
list(registry.subkeys("HKEY_USERS"))
|
|
81
|
+
|
|
82
|
+
assert wire.computer_names == [_REMOTE, _REMOTE]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@pytest.mark.os_agnostic
|
|
86
|
+
def test_creating_and_deleting_keys_on_a_remote_registry_uses_its_connection(wire: _Wire, remote_key: str) -> None:
|
|
87
|
+
with Registry(computer_name=_REMOTE) as registry:
|
|
88
|
+
registry.create_key(f"{remote_key}\\child", parents=True)
|
|
89
|
+
registry.set_value(f"{remote_key}\\child", "v", "x")
|
|
90
|
+
registry.delete_key(remote_key, delete_subkeys=True)
|
|
91
|
+
|
|
92
|
+
assert set(wire.computer_names) == {_REMOTE}
|
|
93
|
+
assert wire.key_call_bases
|
|
94
|
+
assert all(any(base is connection for connection in wire.connections) for base in wire.key_call_bases)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@pytest.mark.os_agnostic
|
|
98
|
+
def test_the_first_remote_connection_binds_the_scope_to_that_computer(wire: _Wire) -> None:
|
|
99
|
+
with Registry() as registry:
|
|
100
|
+
registry._reg_connect("HKLM", computer_name=_REMOTE) # pyright: ignore[reportPrivateUsage] - the binding happens here
|
|
101
|
+
list(registry.subkeys("HKEY_USERS"))
|
|
102
|
+
|
|
103
|
+
assert wire.computer_names == [_REMOTE, _REMOTE]
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@pytest.mark.os_agnostic
|
|
107
|
+
def test_a_registry_refuses_a_second_computer_in_the_same_scope(wire: _Wire) -> None:
|
|
108
|
+
with Registry(computer_name=_REMOTE) as registry:
|
|
109
|
+
registry.get_value(_CURRENT_VERSION, "CurrentBuild")
|
|
110
|
+
|
|
111
|
+
with pytest.raises(RegistryError, match="different Machines"):
|
|
112
|
+
registry._reg_connect("HKCU", computer_name="otherhost") # pyright: ignore[reportPrivateUsage] - the guard lives here
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@pytest.mark.os_agnostic
|
|
116
|
+
def test_the_cli_computer_option_reads_from_that_computer(wire: _Wire) -> None:
|
|
117
|
+
result = CliRunner().invoke(cli_mod.cli, ["--computer", _REMOTE, "get", _CURRENT_VERSION, "CurrentBuild"])
|
|
118
|
+
|
|
119
|
+
assert result.exit_code == 0, result.output
|
|
120
|
+
assert wire.computer_names == [_REMOTE]
|
|
@@ -7,6 +7,7 @@ from collections.abc import Callable, Iterator
|
|
|
7
7
|
import pytest
|
|
8
8
|
from click.testing import CliRunner
|
|
9
9
|
|
|
10
|
+
import lib_registry
|
|
10
11
|
from lib_registry import KeyInfo, Registry, RegValue, ResolvedKey, TypedValue, resolve_key, winreg
|
|
11
12
|
from lib_registry import _cli_helpers as helpers
|
|
12
13
|
|
|
@@ -125,3 +126,18 @@ def test_a_subkey_diff_refuses_a_value_kind() -> None:
|
|
|
125
126
|
def test_diff_kinds_keep_their_wire_values() -> None:
|
|
126
127
|
assert [kind.value for kind in helpers.DiffKind] == ["only_in_a", "only_in_b", "value_differs", "subkey_only_in_a", "subkey_only_in_b"]
|
|
127
128
|
assert json.dumps(helpers.DiffKind.ONLY_IN_A) == '"only_in_a"'
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@pytest.mark.os_agnostic
|
|
132
|
+
@pytest.mark.parametrize("name", ["main_key_hashed_by_name", "hive_names_hashed_by_int", "reg_type_names_hashed_by_int"])
|
|
133
|
+
def test_the_exported_lookup_tables_refuse_writes(name: str) -> None:
|
|
134
|
+
table = getattr(lib_registry, name)
|
|
135
|
+
key = next(iter(table))
|
|
136
|
+
|
|
137
|
+
# A read-only mapping has no item assignment, so Python falls back to the sequence protocol:
|
|
138
|
+
# that raises TypeError, or IndexError first when the key is an HKEY constant too large to be
|
|
139
|
+
# an index. Either way nothing is written.
|
|
140
|
+
with pytest.raises((TypeError, IndexError)):
|
|
141
|
+
table[key] = table[key]
|
|
142
|
+
assert not hasattr(table, "__setitem__")
|
|
143
|
+
assert dict(table)[key] == table[key]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|