From f590557a9dacf7516514e7ebd12afd5fc08d4db9 Mon Sep 17 00:00:00 2001 From: "A.Shpak" Date: Sat, 14 Dec 2024 12:37:23 +0300 Subject: [PATCH 1/3] feat: bump winregistry version --- .github/workflows/test.yml | 2 +- machineid/__init__.py | 20 +++++++++++--------- setup.py | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1806a88..6a188ec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] os: [ubuntu-latest, windows-latest, macos-latest] steps: - name: Checkout diff --git a/machineid/__init__.py b/machineid/__init__.py index 97366d7..19e7427 100644 --- a/machineid/__init__.py +++ b/machineid/__init__.py @@ -34,9 +34,9 @@ from sys import platform try: - from winregistry import WinRegistry + import winregistry except ImportError: - WinRegistry = None + winregistry = None class MachineIdNotFound(RuntimeError): """ @@ -64,14 +64,16 @@ def __read__(path: str) -> str: except IOError: return None -def __reg__(registry: str, key: str) -> str: +def __reg__(key_name: str, value_name: str) -> str: + if winregistry is None: + return None try: - with WinRegistry() as reg: - return reg.read_entry(registry, key) \ - .value \ - .strip() + with winregistry.open_value(key_name, value_name) as reg: + if reg.data and isinstance(reg.data, str): + return reg.data.strip() except OSError: - return None + pass + return None def id(winregistry: bool = True) -> str: """ @@ -82,7 +84,7 @@ def id(winregistry: bool = True) -> str: if platform == 'darwin': id = __exec__("ioreg -d2 -c IOPlatformExpertDevice | awk -F\\\" '/IOPlatformUUID/{print $(NF-1)}'") elif platform in ('win32', 'cygwin', 'msys'): - if winregistry and WinRegistry is not None: + if winregistry and winregistry is not None: id = __reg__(r'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography', 'MachineGuid') else: id = __exec__("powershell.exe -ExecutionPolicy bypass -command (Get-CimInstance -Class Win32_ComputerSystemProduct).UUID") diff --git a/setup.py b/setup.py index 6dfc60a..9e0d46c 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ author=__author__, author_email='oss@keygen.sh', license='MIT', - install_requires=['winregistry; sys_platform == "win32"'], + install_requires=['winregistry>=2.01; sys_platform == "win32"'], packages=['machineid'], package_data={ 'machineid': ['py.typed'], From 5939f888cf5159d373cc07891e401ff00567d3a6 Mon Sep 17 00:00:00 2001 From: "A.Shpak" Date: Sat, 14 Dec 2024 19:12:08 +0300 Subject: [PATCH 2/3] fix winregistry version in setup.py file --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9e0d46c..ccaf88a 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ author=__author__, author_email='oss@keygen.sh', license='MIT', - install_requires=['winregistry>=2.01; sys_platform == "win32"'], + install_requires=['winregistry>=2.0.1,<3.0.0; sys_platform == "win32"'], packages=['machineid'], package_data={ 'machineid': ['py.typed'], From 5ce6daab92ef11f9ef9a524f71face8212b96362 Mon Sep 17 00:00:00 2001 From: "A.Shpak" Date: Sat, 14 Dec 2024 23:30:01 +0300 Subject: [PATCH 3/3] add alias to winregistry lib import --- machineid/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/machineid/__init__.py b/machineid/__init__.py index 19e7427..acc3ec5 100644 --- a/machineid/__init__.py +++ b/machineid/__init__.py @@ -34,9 +34,9 @@ from sys import platform try: - import winregistry + import winregistry as winregistry_lib except ImportError: - winregistry = None + winregistry_lib = None class MachineIdNotFound(RuntimeError): """ @@ -65,10 +65,10 @@ def __read__(path: str) -> str: return None def __reg__(key_name: str, value_name: str) -> str: - if winregistry is None: + if winregistry_lib is None: return None try: - with winregistry.open_value(key_name, value_name) as reg: + with winregistry_lib.open_value(key_name, value_name) as reg: if reg.data and isinstance(reg.data, str): return reg.data.strip() except OSError: @@ -84,7 +84,7 @@ def id(winregistry: bool = True) -> str: if platform == 'darwin': id = __exec__("ioreg -d2 -c IOPlatformExpertDevice | awk -F\\\" '/IOPlatformUUID/{print $(NF-1)}'") elif platform in ('win32', 'cygwin', 'msys'): - if winregistry and winregistry is not None: + if winregistry: id = __reg__(r'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography', 'MachineGuid') else: id = __exec__("powershell.exe -ExecutionPolicy bypass -command (Get-CimInstance -Class Win32_ComputerSystemProduct).UUID")