aboutsummaryrefslogtreecommitdiff
path: root/unixreg/key.py
blob: e50415bec03764cae8c7bbeb8fef286258add086 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
from copy import deepcopy
from typing import TypeVar, Union

from .constants import STANDARD_RIGHTS_REQUIRED

RegKeyT = TypeVar("RegKeyT", bound="RegKey")

_HANDLE_COUNTER = 0

class RegKey:

	def __init__(self, key: str = "", access: int = STANDARD_RIGHTS_REQUIRED):
		global _HANDLE_COUNTER
		_HANDLE_COUNTER += 1

		self.key = key
		self.handle = _HANDLE_COUNTER
		self.access = access

	def __add__(self, other: Union[str, RegKeyT]) -> RegKeyT:
		if isinstance(other, __class__):
			other = other.key

		if isinstance(other, str):
			other = other.replace("\\\\", "\\").replace("\\", os.path.sep)
			retval = deepcopy(self)
			retval.key = os.path.join(self.key, other)
			return retval

		return None

	def __access(self, access):
		self.access = access

	def __enter__(self) -> RegKeyT:
		return self

	def __exit__(self, *args, **kwargs):
		pass

	def __repr__(self):
		return __class__.__name__

	def __str__(self):
		return f"{__class__.__name__}({self.key}, {self.handle}, {self.access})"

	def Close(self):
		pass

	def Detach(self):
		pass


PyHKEY = RegKey