monkeytoolbox 0.1.0__py3-none-any.whl → 0.3.0__py3-none-any.whl
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.
- CHANGELOG.md +11 -4
- monkeytoolbox/__init__.py +8 -12
- monkeytoolbox/decorators.py +1 -1
- monkeytoolbox/environment.py +22 -2
- monkeytoolbox/py.typed +0 -0
- monkeytoolbox/secure_directory.py +3 -5
- monkeytoolbox/secure_file.py +2 -1
- monkeytoolbox/threading.py +24 -19
- {monkeytoolbox-0.1.0.dist-info → monkeytoolbox-0.3.0.dist-info}/METADATA +1 -1
- monkeytoolbox-0.3.0.dist-info/RECORD +17 -0
- monkeytoolbox-0.1.0.dist-info/RECORD +0 -16
- {monkeytoolbox-0.1.0.dist-info → monkeytoolbox-0.3.0.dist-info}/LICENSE +0 -0
- {monkeytoolbox-0.1.0.dist-info → monkeytoolbox-0.3.0.dist-info}/WHEEL +0 -0
CHANGELOG.md
CHANGED
|
@@ -7,9 +7,16 @@ Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
|
|
|
7
7
|
the [PEP 440 version scheme](https://peps.python.org/pep-0440/#version-scheme).
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
## [
|
|
10
|
+
## [v0.3.0 - 2024-01-16]
|
|
11
|
+
### Fixed
|
|
12
|
+
- The location of the `py.typed` file so that type checking is now properly
|
|
13
|
+
supported
|
|
14
|
+
|
|
15
|
+
## [v0.2.0 - 2024-01-04]
|
|
11
16
|
### Added
|
|
17
|
+
- `get_os_version()`
|
|
18
|
+
- `get_hostname()`
|
|
19
|
+
- Support for type checking (py.typed marker file)
|
|
20
|
+
|
|
12
21
|
### Changed
|
|
13
|
-
|
|
14
|
-
### Removed
|
|
15
|
-
### Security
|
|
22
|
+
- `get_os()` raises `RuntimeError` if the operating system is not supported
|
monkeytoolbox/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from .environment import get_os,
|
|
1
|
+
from .environment import get_hardware_id, get_hostname, get_os, get_os_version
|
|
2
2
|
from .decorators import request_cache
|
|
3
3
|
from .code_utils import (
|
|
4
4
|
apply_filters,
|
|
@@ -6,7 +6,7 @@ from .code_utils import (
|
|
|
6
6
|
del_key,
|
|
7
7
|
insecure_generate_random_string,
|
|
8
8
|
secure_generate_random_string,
|
|
9
|
-
PeriodicCaller
|
|
9
|
+
PeriodicCaller,
|
|
10
10
|
)
|
|
11
11
|
from .file_utils import (
|
|
12
12
|
append_bytes,
|
|
@@ -15,20 +15,16 @@ from .file_utils import (
|
|
|
15
15
|
expand_path,
|
|
16
16
|
get_text_file_contents,
|
|
17
17
|
get_all_regular_files_in_directory,
|
|
18
|
-
get_binary_io_sha256_hash
|
|
18
|
+
get_binary_io_sha256_hash,
|
|
19
19
|
)
|
|
20
20
|
from .secure_directory import create_secure_directory
|
|
21
21
|
from .secure_file import open_new_securely_permissioned_file
|
|
22
22
|
from .threading import (
|
|
23
|
-
ThreadSafeIterator,
|
|
24
|
-
InterruptableThreadMixin,
|
|
25
|
-
interruptible_function,
|
|
23
|
+
ThreadSafeIterator,
|
|
24
|
+
InterruptableThreadMixin,
|
|
25
|
+
interruptible_function,
|
|
26
26
|
interruptible_iter,
|
|
27
27
|
create_daemon_thread,
|
|
28
|
-
run_worker_threads
|
|
29
|
-
)
|
|
30
|
-
from .network_utils import (
|
|
31
|
-
port_is_used,
|
|
32
|
-
get_network_interfaces,
|
|
33
|
-
get_my_ip_addresses
|
|
28
|
+
run_worker_threads,
|
|
34
29
|
)
|
|
30
|
+
from .network_utils import port_is_used, get_network_interfaces, get_my_ip_addresses
|
monkeytoolbox/decorators.py
CHANGED
monkeytoolbox/environment.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import platform
|
|
2
|
+
import socket
|
|
2
3
|
import uuid
|
|
3
4
|
from contextlib import suppress
|
|
4
5
|
|
|
@@ -6,10 +7,21 @@ from monkeytypes import HardwareID, OperatingSystem
|
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
def get_os() -> OperatingSystem:
|
|
9
|
-
|
|
10
|
+
"""
|
|
11
|
+
Get the OperatingSystem of the current execution environment.
|
|
12
|
+
|
|
13
|
+
:return: The OperatingSystem of the current execution environment
|
|
14
|
+
:raises: RuntimeError if the current OperatingSystem is not supported
|
|
15
|
+
"""
|
|
16
|
+
system = platform.system()
|
|
17
|
+
|
|
18
|
+
if system == "Windows":
|
|
10
19
|
return OperatingSystem.WINDOWS
|
|
11
20
|
|
|
12
|
-
|
|
21
|
+
if system == "Linux":
|
|
22
|
+
return OperatingSystem.LINUX
|
|
23
|
+
|
|
24
|
+
raise RuntimeError(f"'{system}' is not a supported operating system")
|
|
13
25
|
|
|
14
26
|
|
|
15
27
|
def get_hardware_id() -> HardwareID:
|
|
@@ -36,3 +48,11 @@ def _get_hardware_id_linux() -> HardwareID:
|
|
|
36
48
|
machine_id = uuid.getnode()
|
|
37
49
|
|
|
38
50
|
return machine_id
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def get_os_version() -> str:
|
|
54
|
+
return platform.platform()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def get_hostname():
|
|
58
|
+
return socket.gethostname()
|
monkeytoolbox/py.typed
ADDED
|
File without changes
|
|
@@ -3,10 +3,10 @@ import stat
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
from typing import Callable
|
|
5
5
|
|
|
6
|
-
from . import get_os
|
|
7
|
-
|
|
8
6
|
from monkeytypes import OperatingSystem
|
|
9
7
|
|
|
8
|
+
from . import get_os
|
|
9
|
+
|
|
10
10
|
if get_os() == OperatingSystem.WINDOWS:
|
|
11
11
|
import win32file
|
|
12
12
|
import win32security
|
|
@@ -74,9 +74,7 @@ def _make_existing_directory_secure_windows(path: Path):
|
|
|
74
74
|
|
|
75
75
|
def _create_secure_directory_windows(path: Path):
|
|
76
76
|
security_attributes = win32security.SECURITY_ATTRIBUTES()
|
|
77
|
-
security_attributes.SECURITY_DESCRIPTOR = (
|
|
78
|
-
get_security_descriptor_for_owner_only_permissions()
|
|
79
|
-
)
|
|
77
|
+
security_attributes.SECURITY_DESCRIPTOR = get_security_descriptor_for_owner_only_permissions()
|
|
80
78
|
win32file.CreateDirectory(str(path), security_attributes)
|
|
81
79
|
|
|
82
80
|
|
monkeytoolbox/secure_file.py
CHANGED
|
@@ -4,9 +4,10 @@ import stat
|
|
|
4
4
|
from contextlib import contextmanager
|
|
5
5
|
from typing import Generator
|
|
6
6
|
|
|
7
|
-
from . import get_os
|
|
8
7
|
from monkeytypes import OperatingSystem
|
|
9
8
|
|
|
9
|
+
from . import get_os
|
|
10
|
+
|
|
10
11
|
if get_os() == OperatingSystem.WINDOWS:
|
|
11
12
|
import win32file
|
|
12
13
|
import win32job
|
monkeytoolbox/threading.py
CHANGED
|
@@ -10,25 +10,30 @@ from monkeytypes import Event
|
|
|
10
10
|
logger = logging.getLogger(__name__)
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
class RunWorkerThreads:
|
|
14
|
+
def __init__(self):
|
|
15
|
+
self._counters = {}
|
|
16
|
+
|
|
17
|
+
def __call__(
|
|
18
|
+
self,
|
|
19
|
+
target: Callable[..., None],
|
|
20
|
+
name_prefix: str,
|
|
21
|
+
args: Tuple = (),
|
|
22
|
+
num_workers: int = 2,
|
|
23
|
+
):
|
|
24
|
+
worker_threads = []
|
|
25
|
+
counter = self._counters.setdefault(name_prefix, count(start=1))
|
|
26
|
+
for i in range(0, num_workers):
|
|
27
|
+
name = f"{name_prefix}-{next(counter):02d}"
|
|
28
|
+
t = create_daemon_thread(target=target, name=name, args=args)
|
|
29
|
+
t.start()
|
|
30
|
+
worker_threads.append(t)
|
|
31
|
+
|
|
32
|
+
for t in worker_threads:
|
|
33
|
+
t.join()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
run_worker_threads = RunWorkerThreads()
|
|
32
37
|
|
|
33
38
|
|
|
34
39
|
def create_daemon_thread(target: Callable[..., None], name: str, args: Tuple = ()) -> Thread:
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
CHANGELOG.md,sha256=DiqJ_RNfNl6h1Aqfc-PpuYOcpfv8tzuq36eGruZC0cQ,612
|
|
2
|
+
README.md,sha256=ZOercnjzgT1CcA3bR_6Pg-i-p-xCUYsj7ShRZi_pfg0,309
|
|
3
|
+
monkeytoolbox/__init__.py,sha256=-m9QOksTBVV53-G7_E4Ykyw0QCVwntmKHV0m62P1JqE,873
|
|
4
|
+
monkeytoolbox/code_utils.py,sha256=3JefNrkhMJnxsfFBtKN9Ki9Qa-t_cXeBi7Pu-RfmfOs,5261
|
|
5
|
+
monkeytoolbox/decorators.py,sha256=baXV_UuH-a-3j3RJ3NhFLq0MoVcu6efSblBvEKSilCA,2213
|
|
6
|
+
monkeytoolbox/environment.py,sha256=PozYy9gpHKghQnSStWM0ryFtcsmf02WPXmooelYDHDQ,1550
|
|
7
|
+
monkeytoolbox/file_utils.py,sha256=6fUtFd9k0Eb-5e38fDQAPPGMHqALcpvu8vezhWvH7R0,1868
|
|
8
|
+
monkeytoolbox/network_utils.py,sha256=grdmj8l5hBmTh1Fy9UO1j2j6gIBqsN4i09Zao0785E0,1664
|
|
9
|
+
monkeytoolbox/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
monkeytoolbox/secure_directory.py,sha256=h0gWiho_xSuNZrUp0Bxt_8uzdWkNo3sFMiN-0TFM5o4,2679
|
|
11
|
+
monkeytoolbox/secure_file.py,sha256=b1SVsjC7H6rJNn7eUU2bgeG-5ru0duaaiM1vv7py314,2678
|
|
12
|
+
monkeytoolbox/threading.py,sha256=QYmWERGsRRrFEAcM2pdlNzw3Z-9rTnevTf6LFDOLo8U,4713
|
|
13
|
+
monkeytoolbox/windows_permissions.py,sha256=jym55x5-fvH2t6_BsixUIGAbkk6ovKkHsGkHkjsqWFM,1845
|
|
14
|
+
monkeytoolbox-0.3.0.dist-info/LICENSE,sha256=8vSVUSGQNLw3jNk-6LogMp9dkBcAS103yGyzS78mIjs,35255
|
|
15
|
+
monkeytoolbox-0.3.0.dist-info/METADATA,sha256=dbA9m_djyx3av_liwNxcShiFSqltpXSMydQpKr-YqXA,1078
|
|
16
|
+
monkeytoolbox-0.3.0.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
|
17
|
+
monkeytoolbox-0.3.0.dist-info/RECORD,,
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
CHANGELOG.md,sha256=j-PoKpkEAxKG2Yc69glm5esCQojGbz2FtWjc1840z98,346
|
|
2
|
-
README.md,sha256=ZOercnjzgT1CcA3bR_6Pg-i-p-xCUYsj7ShRZi_pfg0,309
|
|
3
|
-
monkeytoolbox/__init__.py,sha256=tuvDfZx3XsucGnsoLjFaIW7O_iRjRb2L5-NvuuQDPYU,861
|
|
4
|
-
monkeytoolbox/code_utils.py,sha256=3JefNrkhMJnxsfFBtKN9Ki9Qa-t_cXeBi7Pu-RfmfOs,5261
|
|
5
|
-
monkeytoolbox/decorators.py,sha256=qsQZzeugiSJv5nmgVgx4TEfgO1DDgHFUbMopcEv9GgI,2214
|
|
6
|
-
monkeytoolbox/environment.py,sha256=p3IYsFYqlcGj3rVF-Tp4-qaXqD_fQ-MOQw48P460fYo,1067
|
|
7
|
-
monkeytoolbox/file_utils.py,sha256=6fUtFd9k0Eb-5e38fDQAPPGMHqALcpvu8vezhWvH7R0,1868
|
|
8
|
-
monkeytoolbox/network_utils.py,sha256=grdmj8l5hBmTh1Fy9UO1j2j6gIBqsN4i09Zao0785E0,1664
|
|
9
|
-
monkeytoolbox/secure_directory.py,sha256=FMtriWLY04m8YXGHEe_gEZfeCBJ0IpLhmyH8HvN7BCc,2695
|
|
10
|
-
monkeytoolbox/secure_file.py,sha256=aAXwoqtIdhlkykajNqMLmafTt5HeN14f5zrFgbPKcHU,2677
|
|
11
|
-
monkeytoolbox/threading.py,sha256=6Z2PHhLigOXxLOhE3WniabQ5HgNlqQNTTBPM6xi66e4,4578
|
|
12
|
-
monkeytoolbox/windows_permissions.py,sha256=jym55x5-fvH2t6_BsixUIGAbkk6ovKkHsGkHkjsqWFM,1845
|
|
13
|
-
monkeytoolbox-0.1.0.dist-info/LICENSE,sha256=8vSVUSGQNLw3jNk-6LogMp9dkBcAS103yGyzS78mIjs,35255
|
|
14
|
-
monkeytoolbox-0.1.0.dist-info/METADATA,sha256=raF0lxDlgkOIlySAS6GYK9511JEwNe5ODexJtyWKAng,1078
|
|
15
|
-
monkeytoolbox-0.1.0.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
|
16
|
-
monkeytoolbox-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|