From 25853662766e9131ddcbdfaf61c8eb631aadd999 Mon Sep 17 00:00:00 2001 From: "A.Shpak" Date: Wed, 13 Nov 2024 19:23:18 +0300 Subject: [PATCH] - --- winregistry.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/winregistry.py b/winregistry.py index d660628..ef5266c 100644 --- a/winregistry.py +++ b/winregistry.py @@ -15,6 +15,7 @@ 'HKDD': 'HKEY_DYN_DATA', } + def _cast_winreg(value: str) -> tp.Any: if not (obj := getattr(winreg, value)): raise ValueError(f'unknown value {value}') @@ -28,7 +29,7 @@ def _normalize_wow64_32(value): class _RegEntity(ABC): - def __init__(self, reg_key, name, wow64_32: bool| int = False): + def __init__(self, reg_key, name, wow64_32: bool | int = False): self._name = name self._reg_key = reg_key self._wow = _normalize_wow64_32(wow64_32) @@ -42,8 +43,7 @@ def _get_raw(self): ... @classmethod @abstractmethod - def from_index(cls, reg_key, index, wow64_32: bool| int = False) -> tp.Self: - ... + def from_index(cls, reg_key, index, wow64_32: bool | int = False) -> tp.Self: ... def _get_access_key(self, winreg_access_mode) -> int: return winreg_access_mode | self._wow @@ -51,7 +51,7 @@ def _get_access_key(self, winreg_access_mode) -> int: class RegValue(_RegEntity): @classmethod - def from_index(cls, reg_key, index, wow64_32: bool| int = False) -> tp.Self: + def from_index(cls, reg_key, index, wow64_32: bool | int = False) -> tp.Self: name, value, raw_type = winreg.EnumValue(reg_key, index) wow = _normalize_wow64_32(wow64_32) return RegValue( @@ -75,19 +75,18 @@ def data(self, value): def type(self): return self._raw[1] - def delete(self): ... class RegKey(_RegEntity): - def __init__(self, reg_key, name, wow64_32: bool| int = False): + def __init__(self, reg_key, name, wow64_32: bool | int = False): super().__init__(reg_key, name, wow64_32) def _get_raw(self): return winreg.QueryInfoKey(self._reg_key) @classmethod - def from_index(cls, reg_key, index, wow64_32: bool| int = False) -> tp.Self: + def from_index(cls, reg_key, index, wow64_32: bool | int = False) -> tp.Self: name = winreg.EnumKey(reg_key, index) wow = _normalize_wow64_32(wow64_32) return RegKey( @@ -117,7 +116,7 @@ def modified_at(self): return datetime(1601, 1, 1) + timedelta(microseconds=self._raw[2] / 10) @property - def child_keys_names(self) : + def child_keys_names(self): for index in range(self.child_keys_count): yield winreg.EnumKey(self._reg_key, index) @@ -161,7 +160,7 @@ def set_value(self, name, value): ... def delete_value(self, name): ... - def __enter__(self) : + def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): @@ -172,18 +171,13 @@ class WinRegistry(RegKey): @classmethod def connect(cls, name: str | int, host=None, wow64_32=False): if isinstance(name, int): - return cls( - winreg.ConnectRegistry(host, name), - wow64_32 - ) + return cls(winreg.ConnectRegistry(host, name), wow64_32) return cls( winreg.ConnectRegistry(host, _cast_winreg(name.upper())), wow64_32, ) - -# # class robot: # def __init__(self, root, host=None, wow64_32=False): # self._cls_params = {