exonware-xwnode 0.0.1.12__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 +14 -0
- exonware/xwnode/__init__.py +127 -0
- exonware/xwnode/base.py +676 -0
- exonware/xwnode/config.py +178 -0
- exonware/xwnode/contracts.py +730 -0
- exonware/xwnode/errors.py +503 -0
- exonware/xwnode/facade.py +460 -0
- exonware/xwnode/strategies/__init__.py +158 -0
- exonware/xwnode/strategies/advisor.py +463 -0
- exonware/xwnode/strategies/edges/__init__.py +32 -0
- exonware/xwnode/strategies/edges/adj_list.py +227 -0
- exonware/xwnode/strategies/edges/adj_matrix.py +391 -0
- exonware/xwnode/strategies/edges/base.py +169 -0
- exonware/xwnode/strategies/flyweight.py +328 -0
- exonware/xwnode/strategies/impls/__init__.py +13 -0
- exonware/xwnode/strategies/impls/_base_edge.py +403 -0
- exonware/xwnode/strategies/impls/_base_node.py +307 -0
- exonware/xwnode/strategies/impls/edge_adj_list.py +353 -0
- exonware/xwnode/strategies/impls/edge_adj_matrix.py +445 -0
- exonware/xwnode/strategies/impls/edge_bidir_wrapper.py +455 -0
- exonware/xwnode/strategies/impls/edge_block_adj_matrix.py +539 -0
- exonware/xwnode/strategies/impls/edge_coo.py +533 -0
- exonware/xwnode/strategies/impls/edge_csc.py +447 -0
- exonware/xwnode/strategies/impls/edge_csr.py +492 -0
- exonware/xwnode/strategies/impls/edge_dynamic_adj_list.py +503 -0
- exonware/xwnode/strategies/impls/edge_flow_network.py +555 -0
- exonware/xwnode/strategies/impls/edge_hyperedge_set.py +516 -0
- exonware/xwnode/strategies/impls/edge_neural_graph.py +650 -0
- exonware/xwnode/strategies/impls/edge_octree.py +574 -0
- exonware/xwnode/strategies/impls/edge_property_store.py +655 -0
- exonware/xwnode/strategies/impls/edge_quadtree.py +519 -0
- exonware/xwnode/strategies/impls/edge_rtree.py +820 -0
- exonware/xwnode/strategies/impls/edge_temporal_edgeset.py +558 -0
- exonware/xwnode/strategies/impls/edge_tree_graph_basic.py +271 -0
- exonware/xwnode/strategies/impls/edge_weighted_graph.py +411 -0
- exonware/xwnode/strategies/manager.py +775 -0
- exonware/xwnode/strategies/metrics.py +538 -0
- exonware/xwnode/strategies/migration.py +432 -0
- exonware/xwnode/strategies/nodes/__init__.py +50 -0
- exonware/xwnode/strategies/nodes/_base_node.py +307 -0
- exonware/xwnode/strategies/nodes/adjacency_list.py +267 -0
- exonware/xwnode/strategies/nodes/aho_corasick.py +345 -0
- exonware/xwnode/strategies/nodes/array_list.py +209 -0
- exonware/xwnode/strategies/nodes/base.py +247 -0
- exonware/xwnode/strategies/nodes/deque.py +200 -0
- exonware/xwnode/strategies/nodes/hash_map.py +135 -0
- exonware/xwnode/strategies/nodes/heap.py +307 -0
- exonware/xwnode/strategies/nodes/linked_list.py +232 -0
- exonware/xwnode/strategies/nodes/node_aho_corasick.py +520 -0
- exonware/xwnode/strategies/nodes/node_array_list.py +175 -0
- exonware/xwnode/strategies/nodes/node_avl_tree.py +371 -0
- exonware/xwnode/strategies/nodes/node_b_plus_tree.py +542 -0
- exonware/xwnode/strategies/nodes/node_bitmap.py +420 -0
- exonware/xwnode/strategies/nodes/node_bitset_dynamic.py +513 -0
- exonware/xwnode/strategies/nodes/node_bloom_filter.py +347 -0
- exonware/xwnode/strategies/nodes/node_btree.py +357 -0
- exonware/xwnode/strategies/nodes/node_count_min_sketch.py +470 -0
- exonware/xwnode/strategies/nodes/node_cow_tree.py +473 -0
- exonware/xwnode/strategies/nodes/node_cuckoo_hash.py +392 -0
- exonware/xwnode/strategies/nodes/node_fenwick_tree.py +301 -0
- exonware/xwnode/strategies/nodes/node_hash_map.py +269 -0
- exonware/xwnode/strategies/nodes/node_heap.py +191 -0
- exonware/xwnode/strategies/nodes/node_hyperloglog.py +407 -0
- exonware/xwnode/strategies/nodes/node_linked_list.py +409 -0
- exonware/xwnode/strategies/nodes/node_lsm_tree.py +400 -0
- exonware/xwnode/strategies/nodes/node_ordered_map.py +390 -0
- exonware/xwnode/strategies/nodes/node_ordered_map_balanced.py +565 -0
- exonware/xwnode/strategies/nodes/node_patricia.py +512 -0
- exonware/xwnode/strategies/nodes/node_persistent_tree.py +378 -0
- exonware/xwnode/strategies/nodes/node_radix_trie.py +452 -0
- exonware/xwnode/strategies/nodes/node_red_black_tree.py +497 -0
- exonware/xwnode/strategies/nodes/node_roaring_bitmap.py +570 -0
- exonware/xwnode/strategies/nodes/node_segment_tree.py +289 -0
- exonware/xwnode/strategies/nodes/node_set_hash.py +354 -0
- exonware/xwnode/strategies/nodes/node_set_tree.py +480 -0
- exonware/xwnode/strategies/nodes/node_skip_list.py +316 -0
- exonware/xwnode/strategies/nodes/node_splay_tree.py +393 -0
- exonware/xwnode/strategies/nodes/node_suffix_array.py +487 -0
- exonware/xwnode/strategies/nodes/node_treap.py +387 -0
- exonware/xwnode/strategies/nodes/node_tree_graph_hybrid.py +1434 -0
- exonware/xwnode/strategies/nodes/node_trie.py +252 -0
- exonware/xwnode/strategies/nodes/node_union_find.py +187 -0
- exonware/xwnode/strategies/nodes/node_xdata_optimized.py +369 -0
- exonware/xwnode/strategies/nodes/priority_queue.py +209 -0
- exonware/xwnode/strategies/nodes/queue.py +161 -0
- exonware/xwnode/strategies/nodes/sparse_matrix.py +206 -0
- exonware/xwnode/strategies/nodes/stack.py +152 -0
- exonware/xwnode/strategies/nodes/trie.py +274 -0
- exonware/xwnode/strategies/nodes/union_find.py +283 -0
- exonware/xwnode/strategies/pattern_detector.py +603 -0
- exonware/xwnode/strategies/performance_monitor.py +487 -0
- exonware/xwnode/strategies/queries/__init__.py +24 -0
- exonware/xwnode/strategies/queries/base.py +236 -0
- exonware/xwnode/strategies/queries/cql.py +201 -0
- exonware/xwnode/strategies/queries/cypher.py +181 -0
- exonware/xwnode/strategies/queries/datalog.py +70 -0
- exonware/xwnode/strategies/queries/elastic_dsl.py +70 -0
- exonware/xwnode/strategies/queries/eql.py +70 -0
- exonware/xwnode/strategies/queries/flux.py +70 -0
- exonware/xwnode/strategies/queries/gql.py +70 -0
- exonware/xwnode/strategies/queries/graphql.py +240 -0
- exonware/xwnode/strategies/queries/gremlin.py +181 -0
- exonware/xwnode/strategies/queries/hiveql.py +214 -0
- exonware/xwnode/strategies/queries/hql.py +70 -0
- exonware/xwnode/strategies/queries/jmespath.py +219 -0
- exonware/xwnode/strategies/queries/jq.py +66 -0
- exonware/xwnode/strategies/queries/json_query.py +66 -0
- exonware/xwnode/strategies/queries/jsoniq.py +248 -0
- exonware/xwnode/strategies/queries/kql.py +70 -0
- exonware/xwnode/strategies/queries/linq.py +238 -0
- exonware/xwnode/strategies/queries/logql.py +70 -0
- exonware/xwnode/strategies/queries/mql.py +68 -0
- exonware/xwnode/strategies/queries/n1ql.py +210 -0
- exonware/xwnode/strategies/queries/partiql.py +70 -0
- exonware/xwnode/strategies/queries/pig.py +215 -0
- exonware/xwnode/strategies/queries/promql.py +70 -0
- exonware/xwnode/strategies/queries/sparql.py +220 -0
- exonware/xwnode/strategies/queries/sql.py +275 -0
- exonware/xwnode/strategies/queries/xml_query.py +66 -0
- exonware/xwnode/strategies/queries/xpath.py +223 -0
- exonware/xwnode/strategies/queries/xquery.py +258 -0
- exonware/xwnode/strategies/queries/xwnode_executor.py +332 -0
- exonware/xwnode/strategies/queries/xwquery_strategy.py +424 -0
- exonware/xwnode/strategies/registry.py +604 -0
- exonware/xwnode/strategies/simple.py +273 -0
- exonware/xwnode/strategies/utils.py +532 -0
- exonware/xwnode/types.py +912 -0
- exonware/xwnode/version.py +78 -0
- exonware_xwnode-0.0.1.12.dist-info/METADATA +169 -0
- exonware_xwnode-0.0.1.12.dist-info/RECORD +132 -0
- exonware_xwnode-0.0.1.12.dist-info/WHEEL +4 -0
- exonware_xwnode-0.0.1.12.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
"""
|
2
|
+
Configuration management for the xwnode library.
|
3
|
+
|
4
|
+
This module provides a thread-safe, centralized configuration for performance
|
5
|
+
tuning and behavior customization. It supports loading from environment
|
6
|
+
variables and programmatic overrides.
|
7
|
+
"""
|
8
|
+
|
9
|
+
import os
|
10
|
+
import threading
|
11
|
+
from dataclasses import dataclass, fields
|
12
|
+
from typing import Optional
|
13
|
+
|
14
|
+
# Assuming xSystem is in the path. If not, this will gracefully be handled.
|
15
|
+
try:
|
16
|
+
from exonware.xwsystem import get_logger
|
17
|
+
logger = get_logger('xwnode.config')
|
18
|
+
except (ImportError, TypeError):
|
19
|
+
# Fallback logger if xwsystem is not available
|
20
|
+
import logging
|
21
|
+
logger = logging.getLogger('xwnode.config')
|
22
|
+
|
23
|
+
from .errors import XWNodeValueError
|
24
|
+
|
25
|
+
# A lock to ensure thread-safe modification of the global config object
|
26
|
+
_config_lock = threading.Lock()
|
27
|
+
# The global configuration instance
|
28
|
+
_config: Optional['XWNodeConfig'] = None
|
29
|
+
|
30
|
+
|
31
|
+
def _get_env_var(key: str, default: str, target_type: type):
|
32
|
+
"""
|
33
|
+
Safely retrieve and cast an environment variable.
|
34
|
+
|
35
|
+
Args:
|
36
|
+
key: The environment variable name.
|
37
|
+
default: The default value (as a string).
|
38
|
+
target_type: The type to cast the value to (int, float, bool).
|
39
|
+
|
40
|
+
Returns:
|
41
|
+
The casted value.
|
42
|
+
|
43
|
+
Raises:
|
44
|
+
xNodeValueError: If the environment variable has an invalid value.
|
45
|
+
"""
|
46
|
+
value = os.getenv(key, default)
|
47
|
+
try:
|
48
|
+
if target_type is bool:
|
49
|
+
return value.lower() in ('true', '1', 'yes', 'y', 't')
|
50
|
+
if target_type is int:
|
51
|
+
return int(value)
|
52
|
+
if target_type is float:
|
53
|
+
return float(value)
|
54
|
+
return value
|
55
|
+
except (ValueError, TypeError) as e:
|
56
|
+
raise xNodeValueError(
|
57
|
+
f"Invalid value for environment variable {key}: '{value}'. "
|
58
|
+
f"Could not convert to {target_type.__name__}."
|
59
|
+
) from e
|
60
|
+
|
61
|
+
|
62
|
+
@dataclass
|
63
|
+
class XWNodeConfig:
|
64
|
+
"""
|
65
|
+
Configuration for XWNode performance and behavior tuning.
|
66
|
+
|
67
|
+
Defines default values for various operational parameters. These can be
|
68
|
+
overridden by environment variables or by setting a custom config object.
|
69
|
+
"""
|
70
|
+
|
71
|
+
# --- Cache Configuration ---
|
72
|
+
path_cache_size: int = 1024
|
73
|
+
node_pool_size: int = 2000
|
74
|
+
conversion_cache_size: int = 512
|
75
|
+
|
76
|
+
# --- Lazy Loading Thresholds ---
|
77
|
+
lazy_threshold_dict: int = 15
|
78
|
+
lazy_threshold_list: int = 30
|
79
|
+
|
80
|
+
# --- Memory Management ---
|
81
|
+
enable_weak_refs: bool = True
|
82
|
+
enable_object_pooling: bool = True
|
83
|
+
|
84
|
+
# --- Security Limits ---
|
85
|
+
max_depth: int = 100
|
86
|
+
max_nodes: int = 1_000_000
|
87
|
+
max_path_length: int = 1024
|
88
|
+
|
89
|
+
# --- Performance Features ---
|
90
|
+
enable_path_caching: bool = True
|
91
|
+
enable_conversion_caching: bool = True
|
92
|
+
enable_optimized_iteration: bool = True
|
93
|
+
|
94
|
+
# --- Threading ---
|
95
|
+
enable_thread_safety: bool = True
|
96
|
+
lock_timeout: float = 5.0
|
97
|
+
|
98
|
+
@classmethod
|
99
|
+
def from_env(cls) -> 'XWNodeConfig':
|
100
|
+
"""
|
101
|
+
Load configuration from environment variables, with robust type casting.
|
102
|
+
"""
|
103
|
+
logger.debug("Loading XWNode configuration from environment variables.")
|
104
|
+
kwargs = {}
|
105
|
+
for field in fields(cls):
|
106
|
+
env_key = f"XNODE_{field.name.upper()}"
|
107
|
+
kwargs[field.name] = _get_env_var(env_key, str(field.default), field.type)
|
108
|
+
return cls(**kwargs)
|
109
|
+
|
110
|
+
def validate(self) -> None:
|
111
|
+
"""
|
112
|
+
Validate configuration values, raising specific errors on failure.
|
113
|
+
|
114
|
+
Raises:
|
115
|
+
XWNodeValueError: If any configuration value is invalid.
|
116
|
+
"""
|
117
|
+
if self.path_cache_size <= 0:
|
118
|
+
raise XWNodeValueError("path_cache_size must be positive")
|
119
|
+
if self.node_pool_size <= 0:
|
120
|
+
raise XWNodeValueError("node_pool_size must be positive")
|
121
|
+
if self.lazy_threshold_dict < 0:
|
122
|
+
raise XWNodeValueError("lazy_threshold_dict must be non-negative")
|
123
|
+
if self.lazy_threshold_list < 0:
|
124
|
+
raise XWNodeValueError("lazy_threshold_list must be non-negative")
|
125
|
+
if self.max_depth <= 0:
|
126
|
+
raise XWNodeValueError("max_depth must be positive")
|
127
|
+
if self.max_nodes <= 0:
|
128
|
+
raise XWNodeValueError("max_nodes must be positive")
|
129
|
+
if self.max_path_length <= 0:
|
130
|
+
raise XWNodeValueError("max_path_length must be positive")
|
131
|
+
if self.lock_timeout <= 0:
|
132
|
+
raise XWNodeValueError("lock_timeout must be positive")
|
133
|
+
|
134
|
+
|
135
|
+
def get_config() -> XWNodeConfig:
|
136
|
+
"""
|
137
|
+
Get the global, thread-safe XWNode configuration instance.
|
138
|
+
|
139
|
+
Initializes the configuration from environment variables on first call.
|
140
|
+
"""
|
141
|
+
global _config
|
142
|
+
# Fast path to avoid locking if config is already set
|
143
|
+
if _config is not None:
|
144
|
+
return _config
|
145
|
+
|
146
|
+
# Thread-safe initialization
|
147
|
+
with _config_lock:
|
148
|
+
# Check again in case another thread initialized it while we waited for the lock
|
149
|
+
if _config is None:
|
150
|
+
_config = XWNodeConfig.from_env()
|
151
|
+
_config.validate()
|
152
|
+
logger.info(f"Initialized XWNode configuration: {_config}")
|
153
|
+
return _config
|
154
|
+
|
155
|
+
|
156
|
+
def set_config(config: XWNodeConfig) -> None:
|
157
|
+
"""
|
158
|
+
Set the global XWNode configuration. This is a thread-safe operation.
|
159
|
+
|
160
|
+
Args:
|
161
|
+
config: A validated XWNodeConfig instance.
|
162
|
+
"""
|
163
|
+
global _config
|
164
|
+
config.validate()
|
165
|
+
with _config_lock:
|
166
|
+
_config = config
|
167
|
+
logger.info(f"Updated XWNode configuration: {config}")
|
168
|
+
|
169
|
+
|
170
|
+
def reset_config() -> None:
|
171
|
+
"""
|
172
|
+
Reset the global configuration to its default state (loaded from env).
|
173
|
+
This is a thread-safe operation.
|
174
|
+
"""
|
175
|
+
global _config
|
176
|
+
with _config_lock:
|
177
|
+
_config = None
|
178
|
+
logger.info("Reset XWNode configuration. It will be re-initialized on next get_config() call.")
|