Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
A.Shpak committed Nov 13, 2024
1 parent 1ddd55d commit 2585366
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions winregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand All @@ -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)
Expand All @@ -42,16 +43,15 @@ 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


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(
Expand All @@ -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(
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand All @@ -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 = {
Expand Down

0 comments on commit 2585366

Please sign in to comment.