exonware-xwsystem 0.0.1.409__py3-none-any.whl → 0.0.1.411__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.
- exonware/__init__.py +2 -2
- exonware/conf.py +10 -20
- exonware/xwsystem/__init__.py +6 -16
- exonware/xwsystem/caching/__init__.py +1 -1
- exonware/xwsystem/caching/base.py +16 -16
- exonware/xwsystem/caching/bloom_cache.py +5 -5
- exonware/xwsystem/caching/cache_manager.py +2 -2
- exonware/xwsystem/caching/conditional.py +4 -4
- exonware/xwsystem/caching/contracts.py +12 -12
- exonware/xwsystem/caching/decorators.py +2 -2
- exonware/xwsystem/caching/defs.py +1 -1
- exonware/xwsystem/caching/disk_cache.py +4 -4
- exonware/xwsystem/caching/distributed.py +1 -1
- exonware/xwsystem/caching/errors.py +1 -1
- exonware/xwsystem/caching/events.py +8 -8
- exonware/xwsystem/caching/eviction_strategies.py +9 -9
- exonware/xwsystem/caching/fluent.py +1 -1
- exonware/xwsystem/caching/integrity.py +1 -1
- exonware/xwsystem/caching/lfu_cache.py +24 -9
- exonware/xwsystem/caching/lfu_optimized.py +21 -21
- exonware/xwsystem/caching/lru_cache.py +14 -7
- exonware/xwsystem/caching/memory_bounded.py +8 -8
- exonware/xwsystem/caching/metrics_exporter.py +6 -6
- exonware/xwsystem/caching/observable_cache.py +1 -1
- exonware/xwsystem/caching/pluggable_cache.py +9 -9
- exonware/xwsystem/caching/rate_limiter.py +1 -1
- exonware/xwsystem/caching/read_through.py +6 -6
- exonware/xwsystem/caching/secure_cache.py +1 -1
- exonware/xwsystem/caching/serializable.py +3 -3
- exonware/xwsystem/caching/stats.py +7 -7
- exonware/xwsystem/caching/tagging.py +11 -11
- exonware/xwsystem/caching/ttl_cache.py +21 -6
- exonware/xwsystem/caching/two_tier_cache.py +5 -5
- exonware/xwsystem/caching/utils.py +3 -3
- exonware/xwsystem/caching/validation.py +1 -1
- exonware/xwsystem/caching/warming.py +9 -9
- exonware/xwsystem/caching/write_behind.py +5 -5
- exonware/xwsystem/cli/__init__.py +1 -1
- exonware/xwsystem/cli/args.py +10 -10
- exonware/xwsystem/cli/base.py +15 -15
- exonware/xwsystem/cli/colors.py +1 -1
- exonware/xwsystem/cli/console.py +1 -1
- exonware/xwsystem/cli/contracts.py +5 -5
- exonware/xwsystem/cli/defs.py +1 -1
- exonware/xwsystem/cli/errors.py +1 -1
- exonware/xwsystem/cli/progress.py +1 -1
- exonware/xwsystem/cli/prompts.py +1 -1
- exonware/xwsystem/cli/tables.py +7 -7
- exonware/xwsystem/config/__init__.py +1 -1
- exonware/xwsystem/config/base.py +14 -14
- exonware/xwsystem/config/contracts.py +22 -22
- exonware/xwsystem/config/defaults.py +2 -2
- exonware/xwsystem/config/defs.py +1 -1
- exonware/xwsystem/config/errors.py +2 -2
- exonware/xwsystem/config/logging.py +1 -1
- exonware/xwsystem/config/logging_setup.py +2 -2
- exonware/xwsystem/config/performance.py +7 -7
- exonware/xwsystem/config/performance_modes.py +20 -20
- exonware/xwsystem/config/version_manager.py +4 -4
- exonware/xwsystem/{http → http_client}/__init__.py +1 -1
- exonware/xwsystem/{http → http_client}/advanced_client.py +20 -20
- exonware/xwsystem/{http → http_client}/base.py +13 -13
- exonware/xwsystem/{http → http_client}/client.py +43 -43
- exonware/xwsystem/{http → http_client}/contracts.py +5 -5
- exonware/xwsystem/{http → http_client}/defs.py +2 -2
- exonware/xwsystem/{http → http_client}/errors.py +2 -2
- exonware/xwsystem/io/__init__.py +1 -1
- exonware/xwsystem/io/archive/__init__.py +1 -1
- exonware/xwsystem/io/archive/archive.py +5 -5
- exonware/xwsystem/io/archive/archive_files.py +8 -8
- exonware/xwsystem/io/archive/archivers.py +3 -3
- exonware/xwsystem/io/archive/base.py +17 -17
- exonware/xwsystem/io/archive/codec_integration.py +1 -1
- exonware/xwsystem/io/archive/compression.py +1 -1
- exonware/xwsystem/io/archive/formats/__init__.py +1 -1
- exonware/xwsystem/io/archive/formats/brotli_format.py +12 -9
- exonware/xwsystem/io/archive/formats/lz4_format.py +12 -9
- exonware/xwsystem/io/archive/formats/rar.py +12 -9
- exonware/xwsystem/io/archive/formats/sevenzip.py +12 -9
- exonware/xwsystem/io/archive/formats/squashfs_format.py +7 -7
- exonware/xwsystem/io/archive/formats/tar.py +8 -8
- exonware/xwsystem/io/archive/formats/wim_format.py +12 -9
- exonware/xwsystem/io/archive/formats/zip.py +8 -8
- exonware/xwsystem/io/archive/formats/zpaq_format.py +7 -7
- exonware/xwsystem/io/archive/formats/zstandard.py +12 -9
- exonware/xwsystem/io/base.py +17 -17
- exonware/xwsystem/io/codec/__init__.py +1 -1
- exonware/xwsystem/io/codec/base.py +261 -14
- exonware/xwsystem/io/codec/contracts.py +3 -6
- exonware/xwsystem/io/codec/registry.py +29 -29
- exonware/xwsystem/io/common/__init__.py +1 -1
- exonware/xwsystem/io/common/atomic.py +2 -2
- exonware/xwsystem/io/common/base.py +1 -1
- exonware/xwsystem/io/common/lock.py +1 -1
- exonware/xwsystem/io/common/watcher.py +4 -4
- exonware/xwsystem/io/contracts.py +34 -39
- exonware/xwsystem/io/data_operations.py +480 -0
- exonware/xwsystem/io/defs.py +2 -2
- exonware/xwsystem/io/errors.py +32 -3
- exonware/xwsystem/io/facade.py +4 -4
- exonware/xwsystem/io/file/__init__.py +1 -1
- exonware/xwsystem/io/file/base.py +2 -2
- exonware/xwsystem/io/file/conversion.py +1 -1
- exonware/xwsystem/io/file/file.py +10 -8
- exonware/xwsystem/io/file/paged_source.py +8 -1
- exonware/xwsystem/io/file/paging/__init__.py +1 -1
- exonware/xwsystem/io/file/paging/byte_paging.py +1 -1
- exonware/xwsystem/io/file/paging/line_paging.py +1 -1
- exonware/xwsystem/io/file/paging/record_paging.py +1 -1
- exonware/xwsystem/io/file/paging/registry.py +5 -5
- exonware/xwsystem/io/file/source.py +22 -11
- exonware/xwsystem/io/filesystem/__init__.py +1 -1
- exonware/xwsystem/io/filesystem/base.py +1 -1
- exonware/xwsystem/io/filesystem/local.py +9 -1
- exonware/xwsystem/io/folder/__init__.py +1 -1
- exonware/xwsystem/io/folder/base.py +2 -2
- exonware/xwsystem/io/folder/folder.py +6 -6
- exonware/xwsystem/io/serialization/__init__.py +1 -1
- exonware/xwsystem/io/serialization/auto_serializer.py +53 -40
- exonware/xwsystem/io/serialization/base.py +248 -35
- exonware/xwsystem/io/serialization/contracts.py +93 -4
- exonware/xwsystem/io/serialization/defs.py +1 -1
- exonware/xwsystem/io/serialization/errors.py +1 -1
- exonware/xwsystem/io/serialization/flyweight.py +22 -22
- exonware/xwsystem/io/serialization/format_detector.py +18 -15
- exonware/xwsystem/io/serialization/formats/__init__.py +1 -1
- exonware/xwsystem/io/serialization/formats/binary/bson.py +1 -1
- exonware/xwsystem/io/serialization/formats/binary/cbor.py +1 -1
- exonware/xwsystem/io/serialization/formats/binary/marshal.py +1 -1
- exonware/xwsystem/io/serialization/formats/binary/msgpack.py +1 -1
- exonware/xwsystem/io/serialization/formats/binary/pickle.py +1 -1
- exonware/xwsystem/io/serialization/formats/binary/plistlib.py +1 -1
- exonware/xwsystem/io/serialization/formats/database/dbm.py +53 -1
- exonware/xwsystem/io/serialization/formats/database/shelve.py +48 -1
- exonware/xwsystem/io/serialization/formats/database/sqlite3.py +85 -1
- exonware/xwsystem/io/serialization/formats/text/configparser.py +2 -2
- exonware/xwsystem/io/serialization/formats/text/csv.py +2 -2
- exonware/xwsystem/io/serialization/formats/text/formdata.py +2 -2
- exonware/xwsystem/io/serialization/formats/text/json.py +23 -5
- exonware/xwsystem/io/serialization/formats/text/json5.py +98 -13
- exonware/xwsystem/io/serialization/formats/text/jsonlines.py +230 -20
- exonware/xwsystem/io/serialization/formats/text/multipart.py +2 -2
- exonware/xwsystem/io/serialization/formats/text/toml.py +65 -4
- exonware/xwsystem/io/serialization/formats/text/xml.py +451 -69
- exonware/xwsystem/io/serialization/formats/text/yaml.py +52 -2
- exonware/xwsystem/io/serialization/registry.py +5 -5
- exonware/xwsystem/io/serialization/serializer.py +184 -12
- exonware/xwsystem/io/serialization/utils/__init__.py +1 -1
- exonware/xwsystem/io/serialization/utils/path_ops.py +3 -3
- exonware/xwsystem/io/stream/__init__.py +1 -1
- exonware/xwsystem/io/stream/async_operations.py +3 -3
- exonware/xwsystem/io/stream/base.py +3 -7
- exonware/xwsystem/io/stream/codec_io.py +4 -7
- exonware/xwsystem/ipc/async_fabric.py +7 -8
- exonware/xwsystem/ipc/base.py +9 -9
- exonware/xwsystem/ipc/contracts.py +5 -5
- exonware/xwsystem/ipc/defs.py +1 -1
- exonware/xwsystem/ipc/errors.py +2 -2
- exonware/xwsystem/ipc/message_queue.py +4 -6
- exonware/xwsystem/ipc/pipes.py +2 -2
- exonware/xwsystem/ipc/process_manager.py +7 -7
- exonware/xwsystem/ipc/process_pool.py +8 -8
- exonware/xwsystem/ipc/shared_memory.py +7 -7
- exonware/xwsystem/monitoring/base.py +33 -33
- exonware/xwsystem/monitoring/contracts.py +27 -27
- exonware/xwsystem/monitoring/defs.py +1 -1
- exonware/xwsystem/monitoring/error_recovery.py +16 -16
- exonware/xwsystem/monitoring/errors.py +2 -2
- exonware/xwsystem/monitoring/memory_monitor.py +12 -12
- exonware/xwsystem/monitoring/metrics.py +8 -8
- exonware/xwsystem/monitoring/performance_manager_generic.py +20 -20
- exonware/xwsystem/monitoring/performance_monitor.py +11 -11
- exonware/xwsystem/monitoring/performance_validator.py +21 -21
- exonware/xwsystem/monitoring/system_monitor.py +17 -17
- exonware/xwsystem/monitoring/tracing.py +20 -20
- exonware/xwsystem/monitoring/tracker.py +7 -7
- exonware/xwsystem/operations/__init__.py +5 -5
- exonware/xwsystem/operations/base.py +3 -3
- exonware/xwsystem/operations/contracts.py +3 -3
- exonware/xwsystem/operations/defs.py +5 -5
- exonware/xwsystem/operations/diff.py +5 -5
- exonware/xwsystem/operations/merge.py +2 -2
- exonware/xwsystem/operations/patch.py +5 -5
- exonware/xwsystem/patterns/base.py +4 -4
- exonware/xwsystem/patterns/context_manager.py +7 -7
- exonware/xwsystem/patterns/contracts.py +29 -31
- exonware/xwsystem/patterns/defs.py +1 -1
- exonware/xwsystem/patterns/dynamic_facade.py +9 -9
- exonware/xwsystem/patterns/errors.py +10 -10
- exonware/xwsystem/patterns/handler_factory.py +15 -14
- exonware/xwsystem/patterns/import_registry.py +22 -22
- exonware/xwsystem/patterns/object_pool.py +14 -13
- exonware/xwsystem/patterns/registry.py +45 -32
- exonware/xwsystem/plugins/__init__.py +1 -1
- exonware/xwsystem/plugins/base.py +25 -25
- exonware/xwsystem/plugins/contracts.py +28 -28
- exonware/xwsystem/plugins/defs.py +1 -1
- exonware/xwsystem/plugins/errors.py +9 -9
- exonware/xwsystem/runtime/__init__.py +1 -1
- exonware/xwsystem/runtime/base.py +42 -42
- exonware/xwsystem/runtime/contracts.py +9 -9
- exonware/xwsystem/runtime/defs.py +1 -1
- exonware/xwsystem/runtime/env.py +9 -9
- exonware/xwsystem/runtime/errors.py +1 -1
- exonware/xwsystem/runtime/reflection.py +15 -15
- exonware/xwsystem/security/auth.py +47 -15
- exonware/xwsystem/security/base.py +17 -17
- exonware/xwsystem/security/contracts.py +30 -30
- exonware/xwsystem/security/crypto.py +8 -8
- exonware/xwsystem/security/defs.py +1 -1
- exonware/xwsystem/security/errors.py +2 -2
- exonware/xwsystem/security/hazmat.py +7 -7
- exonware/xwsystem/security/path_validator.py +1 -1
- exonware/xwsystem/shared/__init__.py +1 -1
- exonware/xwsystem/shared/base.py +14 -14
- exonware/xwsystem/shared/contracts.py +6 -6
- exonware/xwsystem/shared/defs.py +1 -1
- exonware/xwsystem/shared/errors.py +1 -1
- exonware/xwsystem/structures/__init__.py +1 -1
- exonware/xwsystem/structures/base.py +29 -29
- exonware/xwsystem/structures/circular_detector.py +15 -15
- exonware/xwsystem/structures/contracts.py +9 -9
- exonware/xwsystem/structures/defs.py +1 -1
- exonware/xwsystem/structures/errors.py +2 -2
- exonware/xwsystem/structures/tree_walker.py +8 -8
- exonware/xwsystem/threading/async_primitives.py +7 -7
- exonware/xwsystem/threading/base.py +19 -19
- exonware/xwsystem/threading/contracts.py +13 -13
- exonware/xwsystem/threading/defs.py +1 -1
- exonware/xwsystem/threading/errors.py +2 -2
- exonware/xwsystem/threading/safe_factory.py +13 -12
- exonware/xwsystem/utils/base.py +34 -34
- exonware/xwsystem/utils/contracts.py +9 -9
- exonware/xwsystem/utils/dt/__init__.py +1 -1
- exonware/xwsystem/utils/dt/base.py +6 -6
- exonware/xwsystem/utils/dt/contracts.py +2 -2
- exonware/xwsystem/utils/dt/defs.py +1 -1
- exonware/xwsystem/utils/dt/errors.py +2 -2
- exonware/xwsystem/utils/dt/formatting.py +3 -3
- exonware/xwsystem/utils/dt/humanize.py +2 -2
- exonware/xwsystem/utils/dt/parsing.py +2 -2
- exonware/xwsystem/utils/dt/timezone_utils.py +5 -5
- exonware/xwsystem/utils/errors.py +2 -2
- exonware/xwsystem/utils/test_runner.py +6 -6
- exonware/xwsystem/utils/utils_contracts.py +1 -1
- exonware/xwsystem/validation/__init__.py +1 -1
- exonware/xwsystem/validation/base.py +48 -48
- exonware/xwsystem/validation/contracts.py +8 -8
- exonware/xwsystem/validation/data_validator.py +10 -0
- exonware/xwsystem/validation/declarative.py +15 -15
- exonware/xwsystem/validation/defs.py +1 -1
- exonware/xwsystem/validation/errors.py +2 -2
- exonware/xwsystem/validation/fluent_validator.py +10 -10
- exonware/xwsystem/version.py +2 -2
- {exonware_xwsystem-0.0.1.409.dist-info → exonware_xwsystem-0.0.1.411.dist-info}/METADATA +9 -11
- exonware_xwsystem-0.0.1.411.dist-info/RECORD +274 -0
- {exonware_xwsystem-0.0.1.409.dist-info → exonware_xwsystem-0.0.1.411.dist-info}/WHEEL +1 -1
- exonware/xwsystem/lazy_bootstrap.py +0 -79
- exonware_xwsystem-0.0.1.409.dist-info/RECORD +0 -274
- {exonware_xwsystem-0.0.1.409.dist-info → exonware_xwsystem-0.0.1.411.dist-info}/licenses/LICENSE +0 -0
exonware/xwsystem/runtime/env.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Company: eXonware.com
|
|
3
3
|
Author: Eng. Muhammad AlShehri
|
|
4
4
|
Email: connect@exonware.com
|
|
5
|
-
Version: 0.0.1.
|
|
5
|
+
Version: 0.0.1.411
|
|
6
6
|
Generation Date: September 04, 2025
|
|
7
7
|
|
|
8
8
|
Environment management utilities for runtime configuration and detection.
|
|
@@ -12,11 +12,11 @@ import os
|
|
|
12
12
|
import platform
|
|
13
13
|
import sys
|
|
14
14
|
from pathlib import Path
|
|
15
|
-
from typing import Any,
|
|
15
|
+
from typing import Any, Optional, Union
|
|
16
16
|
|
|
17
17
|
from ..config.logging_setup import get_logger
|
|
18
18
|
|
|
19
|
-
logger = get_logger("
|
|
19
|
+
logger = get_logger("xwsystem.runtime.env")
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class EnvironmentManager:
|
|
@@ -27,11 +27,11 @@ class EnvironmentManager:
|
|
|
27
27
|
|
|
28
28
|
def __init__(self) -> None:
|
|
29
29
|
"""Initialize environment manager."""
|
|
30
|
-
self._cache:
|
|
31
|
-
self._env_vars:
|
|
30
|
+
self._cache: dict[str, Any] = {}
|
|
31
|
+
self._env_vars: dict[str, str] = dict(os.environ)
|
|
32
32
|
|
|
33
33
|
@property
|
|
34
|
-
def platform_info(self) ->
|
|
34
|
+
def platform_info(self) -> dict[str, str]:
|
|
35
35
|
"""Get comprehensive platform information."""
|
|
36
36
|
if 'platform_info' not in self._cache:
|
|
37
37
|
self._cache['platform_info'] = {
|
|
@@ -68,7 +68,7 @@ class EnvironmentManager:
|
|
|
68
68
|
return platform.architecture()[0] == '64bit'
|
|
69
69
|
|
|
70
70
|
@property
|
|
71
|
-
def python_info(self) ->
|
|
71
|
+
def python_info(self) -> dict[str, Any]:
|
|
72
72
|
"""Get Python runtime information."""
|
|
73
73
|
if 'python_info' not in self._cache:
|
|
74
74
|
self._cache['python_info'] = {
|
|
@@ -159,7 +159,7 @@ class EnvironmentManager:
|
|
|
159
159
|
logger.warning(f"Invalid float value for {key}: {value}, using default: {default}")
|
|
160
160
|
return default
|
|
161
161
|
|
|
162
|
-
def get_env_list(self, key: str, separator: str = ',', default: Optional[
|
|
162
|
+
def get_env_list(self, key: str, separator: str = ',', default: Optional[list[str]] = None) -> list[str]:
|
|
163
163
|
"""
|
|
164
164
|
Get environment variable as list.
|
|
165
165
|
|
|
@@ -357,7 +357,7 @@ class EnvironmentManager:
|
|
|
357
357
|
"""Get number of CPU cores."""
|
|
358
358
|
return os.cpu_count() or 1
|
|
359
359
|
|
|
360
|
-
def get_environment_summary(self) ->
|
|
360
|
+
def get_environment_summary(self) -> dict[str, Any]:
|
|
361
361
|
"""Get comprehensive environment summary."""
|
|
362
362
|
return {
|
|
363
363
|
'platform': self.platform_info,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Company: eXonware.com
|
|
3
3
|
Author: Eng. Muhammad AlShehri
|
|
4
4
|
Email: connect@exonware.com
|
|
5
|
-
Version: 0.0.1.
|
|
5
|
+
Version: 0.0.1.411
|
|
6
6
|
Generation Date: September 04, 2025
|
|
7
7
|
|
|
8
8
|
Reflection utilities for dynamic code inspection and manipulation.
|
|
@@ -12,11 +12,11 @@ import importlib
|
|
|
12
12
|
import inspect
|
|
13
13
|
import sys
|
|
14
14
|
from pathlib import Path
|
|
15
|
-
from typing import Any, Callable,
|
|
15
|
+
from typing import Any, Callable, Optional, Union
|
|
16
16
|
|
|
17
17
|
from ..config.logging_setup import get_logger
|
|
18
18
|
|
|
19
|
-
logger = get_logger("
|
|
19
|
+
logger = get_logger("xwsystem.runtime.reflection")
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class ReflectionUtils:
|
|
@@ -26,7 +26,7 @@ class ReflectionUtils:
|
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
28
|
@staticmethod
|
|
29
|
-
def get_class_info(cls:
|
|
29
|
+
def get_class_info(cls: type) -> dict[str, Any]:
|
|
30
30
|
"""
|
|
31
31
|
Get comprehensive information about a class.
|
|
32
32
|
|
|
@@ -53,7 +53,7 @@ class ReflectionUtils:
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
@staticmethod
|
|
56
|
-
def get_function_info(func: Callable) ->
|
|
56
|
+
def get_function_info(func: Callable) -> dict[str, Any]:
|
|
57
57
|
"""
|
|
58
58
|
Get comprehensive information about a function.
|
|
59
59
|
|
|
@@ -87,7 +87,7 @@ class ReflectionUtils:
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
@staticmethod
|
|
90
|
-
def get_module_info(module: Any) ->
|
|
90
|
+
def get_module_info(module: Any) -> dict[str, Any]:
|
|
91
91
|
"""
|
|
92
92
|
Get comprehensive information about a module.
|
|
93
93
|
|
|
@@ -113,7 +113,7 @@ class ReflectionUtils:
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
@staticmethod
|
|
116
|
-
def _get_source_lines(obj: Any) -> Optional[
|
|
116
|
+
def _get_source_lines(obj: Any) -> Optional[dict[str, Any]]:
|
|
117
117
|
"""Get source lines for an object."""
|
|
118
118
|
try:
|
|
119
119
|
source_lines, start_line = inspect.getsourcelines(obj)
|
|
@@ -164,7 +164,7 @@ class ReflectionUtils:
|
|
|
164
164
|
raise
|
|
165
165
|
|
|
166
166
|
@staticmethod
|
|
167
|
-
def get_class_from_string(class_path: str) ->
|
|
167
|
+
def get_class_from_string(class_path: str) -> type:
|
|
168
168
|
"""
|
|
169
169
|
Get class from string path.
|
|
170
170
|
|
|
@@ -240,7 +240,7 @@ class ReflectionUtils:
|
|
|
240
240
|
return func(*args, **kwargs)
|
|
241
241
|
|
|
242
242
|
@staticmethod
|
|
243
|
-
def find_classes_in_module(module: Any, base_class: Optional[
|
|
243
|
+
def find_classes_in_module(module: Any, base_class: Optional[type] = None) -> list[type]:
|
|
244
244
|
"""
|
|
245
245
|
Find all classes in a module, optionally filtered by base class.
|
|
246
246
|
|
|
@@ -259,7 +259,7 @@ class ReflectionUtils:
|
|
|
259
259
|
return classes
|
|
260
260
|
|
|
261
261
|
@staticmethod
|
|
262
|
-
def find_functions_in_module(module: Any, decorator: Optional[Any] = None) ->
|
|
262
|
+
def find_functions_in_module(module: Any, decorator: Optional[Any] = None) -> list[Callable]:
|
|
263
263
|
"""
|
|
264
264
|
Find all functions in a module, optionally filtered by decorator.
|
|
265
265
|
|
|
@@ -278,7 +278,7 @@ class ReflectionUtils:
|
|
|
278
278
|
return functions
|
|
279
279
|
|
|
280
280
|
@staticmethod
|
|
281
|
-
def get_all_subclasses(cls:
|
|
281
|
+
def get_all_subclasses(cls: type) -> list[type]:
|
|
282
282
|
"""
|
|
283
283
|
Get all subclasses of a class recursively.
|
|
284
284
|
|
|
@@ -313,7 +313,7 @@ class ReflectionUtils:
|
|
|
313
313
|
return False
|
|
314
314
|
|
|
315
315
|
@staticmethod
|
|
316
|
-
def get_method_resolution_order(cls:
|
|
316
|
+
def get_method_resolution_order(cls: type) -> list[str]:
|
|
317
317
|
"""
|
|
318
318
|
Get method resolution order for a class.
|
|
319
319
|
|
|
@@ -339,7 +339,7 @@ class ReflectionUtils:
|
|
|
339
339
|
return sys.getsizeof(obj)
|
|
340
340
|
|
|
341
341
|
@staticmethod
|
|
342
|
-
def get_module_dependencies(module_name: str) ->
|
|
342
|
+
def get_module_dependencies(module_name: str) -> list[str]:
|
|
343
343
|
"""
|
|
344
344
|
Get list of modules that a module depends on.
|
|
345
345
|
|
|
@@ -377,7 +377,7 @@ class ReflectionUtils:
|
|
|
377
377
|
return dependencies
|
|
378
378
|
|
|
379
379
|
@staticmethod
|
|
380
|
-
def get_runtime_info() ->
|
|
380
|
+
def get_runtime_info() -> dict[str, Any]:
|
|
381
381
|
"""
|
|
382
382
|
Get comprehensive runtime reflection information.
|
|
383
383
|
|
|
@@ -393,7 +393,7 @@ class ReflectionUtils:
|
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
@staticmethod
|
|
396
|
-
def _get_current_frame_info() ->
|
|
396
|
+
def _get_current_frame_info() -> dict[str, Any]:
|
|
397
397
|
"""Get information about the current execution frame."""
|
|
398
398
|
frame = inspect.currentframe()
|
|
399
399
|
if frame and frame.f_back:
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Company: eXonware.com
|
|
3
3
|
Author: Eng. Muhammad AlShehri
|
|
4
4
|
Email: connect@exonware.com
|
|
5
|
-
Version: 0.0.1.
|
|
5
|
+
Version: 0.0.1.411
|
|
6
6
|
Generation Date: September 04, 2025
|
|
7
7
|
|
|
8
8
|
Advanced Authentication Providers for Enterprise Integration
|
|
@@ -20,17 +20,38 @@ import time
|
|
|
20
20
|
import base64
|
|
21
21
|
import hashlib
|
|
22
22
|
import hmac
|
|
23
|
-
from typing import Any,
|
|
23
|
+
from typing import Any, Optional, Union
|
|
24
24
|
from urllib.parse import urlencode, parse_qs
|
|
25
25
|
from .base import AAuthProvider, ATokenInfo, AUserInfo
|
|
26
26
|
from .errors import AuthenticationError, AuthorizationError, TokenExpiredError
|
|
27
27
|
from .defs import OAuth2GrantType
|
|
28
28
|
|
|
29
|
-
import jwt
|
|
30
|
-
import requests
|
|
31
|
-
|
|
32
29
|
from ..config.logging_setup import get_logger
|
|
33
30
|
|
|
31
|
+
# Lazy imports to avoid import errors during test collection
|
|
32
|
+
# These are only imported when actually needed
|
|
33
|
+
def _get_jwt():
|
|
34
|
+
"""Lazy import jwt module."""
|
|
35
|
+
try:
|
|
36
|
+
import jwt
|
|
37
|
+
return jwt
|
|
38
|
+
except ImportError:
|
|
39
|
+
raise ImportError(
|
|
40
|
+
"PyJWT is required for JWT authentication. "
|
|
41
|
+
"Install it with: pip install PyJWT"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
def _get_requests():
|
|
45
|
+
"""Lazy import requests module."""
|
|
46
|
+
try:
|
|
47
|
+
import requests
|
|
48
|
+
return requests
|
|
49
|
+
except ImportError:
|
|
50
|
+
raise ImportError(
|
|
51
|
+
"requests is required for OAuth2 authentication. "
|
|
52
|
+
"Install it with: pip install requests"
|
|
53
|
+
)
|
|
54
|
+
|
|
34
55
|
logger = get_logger("xwsystem.security.auth")
|
|
35
56
|
|
|
36
57
|
|
|
@@ -44,7 +65,7 @@ class OAuth2Provider(AAuthProvider):
|
|
|
44
65
|
authorization_url: str,
|
|
45
66
|
token_url: str,
|
|
46
67
|
userinfo_url: Optional[str] = None,
|
|
47
|
-
scopes: Optional[
|
|
68
|
+
scopes: Optional[list[str]] = None
|
|
48
69
|
):
|
|
49
70
|
"""
|
|
50
71
|
Initialize OAuth2 provider.
|
|
@@ -80,7 +101,7 @@ class OAuth2Provider(AAuthProvider):
|
|
|
80
101
|
|
|
81
102
|
return f"{self.authorization_url}?{urlencode(params)}"
|
|
82
103
|
|
|
83
|
-
async def authenticate(self, credentials:
|
|
104
|
+
async def authenticate(self, credentials: dict[str, Any]) -> ATokenInfo:
|
|
84
105
|
"""Authenticate using OAuth2 flow."""
|
|
85
106
|
import asyncio
|
|
86
107
|
|
|
@@ -98,8 +119,9 @@ class OAuth2Provider(AAuthProvider):
|
|
|
98
119
|
|
|
99
120
|
return await asyncio.to_thread(_authenticate)
|
|
100
121
|
|
|
101
|
-
def _authenticate_authorization_code(self, credentials:
|
|
122
|
+
def _authenticate_authorization_code(self, credentials: dict[str, Any]) -> ATokenInfo:
|
|
102
123
|
"""Authenticate using authorization code."""
|
|
124
|
+
requests = _get_requests()
|
|
103
125
|
data = {
|
|
104
126
|
'grant_type': OAuth2GrantType.AUTHORIZATION_CODE.value,
|
|
105
127
|
'client_id': self.client_id,
|
|
@@ -124,6 +146,7 @@ class OAuth2Provider(AAuthProvider):
|
|
|
124
146
|
|
|
125
147
|
def _authenticate_client_credentials(self) -> ATokenInfo:
|
|
126
148
|
"""Authenticate using client credentials."""
|
|
149
|
+
requests = _get_requests()
|
|
127
150
|
data = {
|
|
128
151
|
'grant_type': OAuth2GrantType.CLIENT_CREDENTIALS.value,
|
|
129
152
|
'client_id': self.client_id,
|
|
@@ -144,8 +167,9 @@ class OAuth2Provider(AAuthProvider):
|
|
|
144
167
|
scope=token_data.get('scope')
|
|
145
168
|
)
|
|
146
169
|
|
|
147
|
-
def _authenticate_resource_owner(self, credentials:
|
|
170
|
+
def _authenticate_resource_owner(self, credentials: dict[str, Any]) -> ATokenInfo:
|
|
148
171
|
"""Authenticate using resource owner credentials."""
|
|
172
|
+
requests = _get_requests()
|
|
149
173
|
data = {
|
|
150
174
|
'grant_type': OAuth2GrantType.RESOURCE_OWNER.value,
|
|
151
175
|
'client_id': self.client_id,
|
|
@@ -177,6 +201,7 @@ class OAuth2Provider(AAuthProvider):
|
|
|
177
201
|
import asyncio
|
|
178
202
|
|
|
179
203
|
def _validate():
|
|
204
|
+
requests = _get_requests()
|
|
180
205
|
headers = {'Authorization': f'Bearer {token}'}
|
|
181
206
|
response = requests.get(self.userinfo_url, headers=headers)
|
|
182
207
|
|
|
@@ -200,6 +225,7 @@ class OAuth2Provider(AAuthProvider):
|
|
|
200
225
|
import asyncio
|
|
201
226
|
|
|
202
227
|
def _refresh():
|
|
228
|
+
requests = _get_requests()
|
|
203
229
|
data = {
|
|
204
230
|
'grant_type': OAuth2GrantType.REFRESH_TOKEN.value,
|
|
205
231
|
'client_id': self.client_id,
|
|
@@ -253,11 +279,12 @@ class JWTProvider(AAuthProvider):
|
|
|
253
279
|
self.audience = audience
|
|
254
280
|
self.expiration_time = expiration_time
|
|
255
281
|
|
|
256
|
-
async def authenticate(self, credentials:
|
|
282
|
+
async def authenticate(self, credentials: dict[str, Any]) -> ATokenInfo:
|
|
257
283
|
"""Create JWT token from user credentials."""
|
|
258
284
|
import asyncio
|
|
259
285
|
|
|
260
286
|
def _authenticate():
|
|
287
|
+
jwt = _get_jwt()
|
|
261
288
|
# In a real implementation, you'd validate credentials against a database
|
|
262
289
|
user_id = credentials.get('user_id')
|
|
263
290
|
if not user_id:
|
|
@@ -291,6 +318,7 @@ class JWTProvider(AAuthProvider):
|
|
|
291
318
|
import asyncio
|
|
292
319
|
|
|
293
320
|
def _validate():
|
|
321
|
+
jwt = _get_jwt()
|
|
294
322
|
try:
|
|
295
323
|
payload = jwt.decode(
|
|
296
324
|
token,
|
|
@@ -317,6 +345,7 @@ class JWTProvider(AAuthProvider):
|
|
|
317
345
|
|
|
318
346
|
async def refresh_token(self, refresh_token: str) -> ATokenInfo:
|
|
319
347
|
"""Refresh JWT token (create new token from existing)."""
|
|
348
|
+
jwt = _get_jwt()
|
|
320
349
|
try:
|
|
321
350
|
# Validate existing token (ignore expiration for refresh)
|
|
322
351
|
payload = jwt.decode(
|
|
@@ -341,8 +370,11 @@ class JWTProvider(AAuthProvider):
|
|
|
341
370
|
expires_in=self.expiration_time
|
|
342
371
|
)
|
|
343
372
|
|
|
344
|
-
except
|
|
345
|
-
|
|
373
|
+
except Exception as e:
|
|
374
|
+
jwt_module = _get_jwt()
|
|
375
|
+
if isinstance(e, jwt_module.InvalidTokenError):
|
|
376
|
+
raise AuthenticationError(f"Invalid refresh token: {e}")
|
|
377
|
+
raise
|
|
346
378
|
|
|
347
379
|
|
|
348
380
|
class SAMLProvider(AAuthProvider):
|
|
@@ -368,7 +400,7 @@ class SAMLProvider(AAuthProvider):
|
|
|
368
400
|
|
|
369
401
|
logger.warning("SAML provider is a simplified implementation. Use a full SAML library for production.")
|
|
370
402
|
|
|
371
|
-
async def authenticate(self, credentials:
|
|
403
|
+
async def authenticate(self, credentials: dict[str, Any]) -> ATokenInfo:
|
|
372
404
|
"""Authenticate using SAML (simplified)."""
|
|
373
405
|
# This is a placeholder implementation
|
|
374
406
|
# In practice, you'd use a library like python3-saml
|
|
@@ -424,7 +456,7 @@ class EnterpriseAuth:
|
|
|
424
456
|
|
|
425
457
|
return self._providers[name]
|
|
426
458
|
|
|
427
|
-
async def authenticate(self, credentials:
|
|
459
|
+
async def authenticate(self, credentials: dict[str, Any], provider: Optional[str] = None) -> ATokenInfo:
|
|
428
460
|
"""Authenticate using specified or active provider."""
|
|
429
461
|
provider_instance = self.get_provider(provider)
|
|
430
462
|
return await provider_instance.authenticate(credentials)
|
|
@@ -439,7 +471,7 @@ class EnterpriseAuth:
|
|
|
439
471
|
provider_instance = self.get_provider(provider)
|
|
440
472
|
return await provider_instance.refresh_token(refresh_token)
|
|
441
473
|
|
|
442
|
-
def list_providers(self) ->
|
|
474
|
+
def list_providers(self) -> list[str]:
|
|
443
475
|
"""List available providers."""
|
|
444
476
|
return list(self._providers.keys())
|
|
445
477
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
#exonware/
|
|
1
|
+
#exonware/xwsystem/security/base.py
|
|
2
2
|
"""
|
|
3
3
|
Company: eXonware.com
|
|
4
4
|
Author: Eng. Muhammad AlShehri
|
|
5
5
|
Email: connect@exonware.com
|
|
6
|
-
Version: 0.0.1.
|
|
6
|
+
Version: 0.0.1.411
|
|
7
7
|
Generation Date: September 04, 2025
|
|
8
8
|
|
|
9
9
|
Security module base classes - abstract classes for security functionality.
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
12
|
from abc import ABC, abstractmethod
|
|
13
|
-
from typing import Any,
|
|
13
|
+
from typing import Any, Optional, Union
|
|
14
14
|
from .defs import HashAlgorithm, EncryptionAlgorithm, SecurityLevel
|
|
15
15
|
|
|
16
16
|
|
|
@@ -118,7 +118,7 @@ class AHashBase(ABC):
|
|
|
118
118
|
pass
|
|
119
119
|
|
|
120
120
|
@abstractmethod
|
|
121
|
-
def hash_with_salt(self, data: Union[str, bytes]) ->
|
|
121
|
+
def hash_with_salt(self, data: Union[str, bytes]) -> tuple[str, bytes]:
|
|
122
122
|
"""Hash data with generated salt."""
|
|
123
123
|
pass
|
|
124
124
|
|
|
@@ -189,8 +189,8 @@ class APathValidatorBase(ABC):
|
|
|
189
189
|
security_level: Security level for validation
|
|
190
190
|
"""
|
|
191
191
|
self.security_level = security_level
|
|
192
|
-
self._allowed_paths:
|
|
193
|
-
self._blocked_paths:
|
|
192
|
+
self._allowed_paths: list[str] = []
|
|
193
|
+
self._blocked_paths: list[str] = []
|
|
194
194
|
|
|
195
195
|
@abstractmethod
|
|
196
196
|
def validate_path(self, path: Union[str, bytes]) -> bool:
|
|
@@ -238,12 +238,12 @@ class APathValidatorBase(ABC):
|
|
|
238
238
|
pass
|
|
239
239
|
|
|
240
240
|
@abstractmethod
|
|
241
|
-
def get_allowed_paths(self) ->
|
|
241
|
+
def get_allowed_paths(self) -> list[str]:
|
|
242
242
|
"""Get allowed paths."""
|
|
243
243
|
pass
|
|
244
244
|
|
|
245
245
|
@abstractmethod
|
|
246
|
-
def get_blocked_paths(self) ->
|
|
246
|
+
def get_blocked_paths(self) -> list[str]:
|
|
247
247
|
"""Get blocked paths."""
|
|
248
248
|
pass
|
|
249
249
|
|
|
@@ -253,8 +253,8 @@ class AResourceLimitsBase(ABC):
|
|
|
253
253
|
|
|
254
254
|
def __init__(self):
|
|
255
255
|
"""Initialize resource limits."""
|
|
256
|
-
self._limits:
|
|
257
|
-
self._current_usage:
|
|
256
|
+
self._limits: dict[str, int] = {}
|
|
257
|
+
self._current_usage: dict[str, int] = {}
|
|
258
258
|
|
|
259
259
|
@abstractmethod
|
|
260
260
|
def set_limit(self, resource: str, limit: int) -> None:
|
|
@@ -297,12 +297,12 @@ class AResourceLimitsBase(ABC):
|
|
|
297
297
|
pass
|
|
298
298
|
|
|
299
299
|
@abstractmethod
|
|
300
|
-
def get_all_limits(self) ->
|
|
300
|
+
def get_all_limits(self) -> dict[str, int]:
|
|
301
301
|
"""Get all resource limits."""
|
|
302
302
|
pass
|
|
303
303
|
|
|
304
304
|
@abstractmethod
|
|
305
|
-
def get_all_usage(self) ->
|
|
305
|
+
def get_all_usage(self) -> dict[str, int]:
|
|
306
306
|
"""Get all resource usage."""
|
|
307
307
|
pass
|
|
308
308
|
|
|
@@ -323,7 +323,7 @@ class ASecurityValidatorBase(ABC):
|
|
|
323
323
|
security_level: Security level for validation
|
|
324
324
|
"""
|
|
325
325
|
self.security_level = security_level
|
|
326
|
-
self._validation_rules:
|
|
326
|
+
self._validation_rules: dict[str, callable] = {}
|
|
327
327
|
|
|
328
328
|
@abstractmethod
|
|
329
329
|
def validate_input(self, data: Any, input_type: str) -> bool:
|
|
@@ -351,7 +351,7 @@ class ASecurityValidatorBase(ABC):
|
|
|
351
351
|
pass
|
|
352
352
|
|
|
353
353
|
@abstractmethod
|
|
354
|
-
def get_validation_errors(self) ->
|
|
354
|
+
def get_validation_errors(self) -> list[str]:
|
|
355
355
|
"""Get validation errors."""
|
|
356
356
|
pass
|
|
357
357
|
|
|
@@ -394,15 +394,15 @@ class AUserInfo:
|
|
|
394
394
|
user_id: str
|
|
395
395
|
username: Optional[str] = None
|
|
396
396
|
email: Optional[str] = None
|
|
397
|
-
roles:
|
|
398
|
-
attributes:
|
|
397
|
+
roles: list[str] = field(default_factory=list)
|
|
398
|
+
attributes: dict[str, Any] = field(default_factory=dict)
|
|
399
399
|
|
|
400
400
|
|
|
401
401
|
class AAuthProvider(ABC):
|
|
402
402
|
"""Abstract base class for authentication providers."""
|
|
403
403
|
|
|
404
404
|
@abstractmethod
|
|
405
|
-
async def authenticate(self, credentials:
|
|
405
|
+
async def authenticate(self, credentials: dict[str, Any]) -> ATokenInfo:
|
|
406
406
|
"""Authenticate user with credentials."""
|
|
407
407
|
pass
|
|
408
408
|
|