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.
Files changed (132) hide show
  1. exonware/__init__.py +14 -0
  2. exonware/xwnode/__init__.py +127 -0
  3. exonware/xwnode/base.py +676 -0
  4. exonware/xwnode/config.py +178 -0
  5. exonware/xwnode/contracts.py +730 -0
  6. exonware/xwnode/errors.py +503 -0
  7. exonware/xwnode/facade.py +460 -0
  8. exonware/xwnode/strategies/__init__.py +158 -0
  9. exonware/xwnode/strategies/advisor.py +463 -0
  10. exonware/xwnode/strategies/edges/__init__.py +32 -0
  11. exonware/xwnode/strategies/edges/adj_list.py +227 -0
  12. exonware/xwnode/strategies/edges/adj_matrix.py +391 -0
  13. exonware/xwnode/strategies/edges/base.py +169 -0
  14. exonware/xwnode/strategies/flyweight.py +328 -0
  15. exonware/xwnode/strategies/impls/__init__.py +13 -0
  16. exonware/xwnode/strategies/impls/_base_edge.py +403 -0
  17. exonware/xwnode/strategies/impls/_base_node.py +307 -0
  18. exonware/xwnode/strategies/impls/edge_adj_list.py +353 -0
  19. exonware/xwnode/strategies/impls/edge_adj_matrix.py +445 -0
  20. exonware/xwnode/strategies/impls/edge_bidir_wrapper.py +455 -0
  21. exonware/xwnode/strategies/impls/edge_block_adj_matrix.py +539 -0
  22. exonware/xwnode/strategies/impls/edge_coo.py +533 -0
  23. exonware/xwnode/strategies/impls/edge_csc.py +447 -0
  24. exonware/xwnode/strategies/impls/edge_csr.py +492 -0
  25. exonware/xwnode/strategies/impls/edge_dynamic_adj_list.py +503 -0
  26. exonware/xwnode/strategies/impls/edge_flow_network.py +555 -0
  27. exonware/xwnode/strategies/impls/edge_hyperedge_set.py +516 -0
  28. exonware/xwnode/strategies/impls/edge_neural_graph.py +650 -0
  29. exonware/xwnode/strategies/impls/edge_octree.py +574 -0
  30. exonware/xwnode/strategies/impls/edge_property_store.py +655 -0
  31. exonware/xwnode/strategies/impls/edge_quadtree.py +519 -0
  32. exonware/xwnode/strategies/impls/edge_rtree.py +820 -0
  33. exonware/xwnode/strategies/impls/edge_temporal_edgeset.py +558 -0
  34. exonware/xwnode/strategies/impls/edge_tree_graph_basic.py +271 -0
  35. exonware/xwnode/strategies/impls/edge_weighted_graph.py +411 -0
  36. exonware/xwnode/strategies/manager.py +775 -0
  37. exonware/xwnode/strategies/metrics.py +538 -0
  38. exonware/xwnode/strategies/migration.py +432 -0
  39. exonware/xwnode/strategies/nodes/__init__.py +50 -0
  40. exonware/xwnode/strategies/nodes/_base_node.py +307 -0
  41. exonware/xwnode/strategies/nodes/adjacency_list.py +267 -0
  42. exonware/xwnode/strategies/nodes/aho_corasick.py +345 -0
  43. exonware/xwnode/strategies/nodes/array_list.py +209 -0
  44. exonware/xwnode/strategies/nodes/base.py +247 -0
  45. exonware/xwnode/strategies/nodes/deque.py +200 -0
  46. exonware/xwnode/strategies/nodes/hash_map.py +135 -0
  47. exonware/xwnode/strategies/nodes/heap.py +307 -0
  48. exonware/xwnode/strategies/nodes/linked_list.py +232 -0
  49. exonware/xwnode/strategies/nodes/node_aho_corasick.py +520 -0
  50. exonware/xwnode/strategies/nodes/node_array_list.py +175 -0
  51. exonware/xwnode/strategies/nodes/node_avl_tree.py +371 -0
  52. exonware/xwnode/strategies/nodes/node_b_plus_tree.py +542 -0
  53. exonware/xwnode/strategies/nodes/node_bitmap.py +420 -0
  54. exonware/xwnode/strategies/nodes/node_bitset_dynamic.py +513 -0
  55. exonware/xwnode/strategies/nodes/node_bloom_filter.py +347 -0
  56. exonware/xwnode/strategies/nodes/node_btree.py +357 -0
  57. exonware/xwnode/strategies/nodes/node_count_min_sketch.py +470 -0
  58. exonware/xwnode/strategies/nodes/node_cow_tree.py +473 -0
  59. exonware/xwnode/strategies/nodes/node_cuckoo_hash.py +392 -0
  60. exonware/xwnode/strategies/nodes/node_fenwick_tree.py +301 -0
  61. exonware/xwnode/strategies/nodes/node_hash_map.py +269 -0
  62. exonware/xwnode/strategies/nodes/node_heap.py +191 -0
  63. exonware/xwnode/strategies/nodes/node_hyperloglog.py +407 -0
  64. exonware/xwnode/strategies/nodes/node_linked_list.py +409 -0
  65. exonware/xwnode/strategies/nodes/node_lsm_tree.py +400 -0
  66. exonware/xwnode/strategies/nodes/node_ordered_map.py +390 -0
  67. exonware/xwnode/strategies/nodes/node_ordered_map_balanced.py +565 -0
  68. exonware/xwnode/strategies/nodes/node_patricia.py +512 -0
  69. exonware/xwnode/strategies/nodes/node_persistent_tree.py +378 -0
  70. exonware/xwnode/strategies/nodes/node_radix_trie.py +452 -0
  71. exonware/xwnode/strategies/nodes/node_red_black_tree.py +497 -0
  72. exonware/xwnode/strategies/nodes/node_roaring_bitmap.py +570 -0
  73. exonware/xwnode/strategies/nodes/node_segment_tree.py +289 -0
  74. exonware/xwnode/strategies/nodes/node_set_hash.py +354 -0
  75. exonware/xwnode/strategies/nodes/node_set_tree.py +480 -0
  76. exonware/xwnode/strategies/nodes/node_skip_list.py +316 -0
  77. exonware/xwnode/strategies/nodes/node_splay_tree.py +393 -0
  78. exonware/xwnode/strategies/nodes/node_suffix_array.py +487 -0
  79. exonware/xwnode/strategies/nodes/node_treap.py +387 -0
  80. exonware/xwnode/strategies/nodes/node_tree_graph_hybrid.py +1434 -0
  81. exonware/xwnode/strategies/nodes/node_trie.py +252 -0
  82. exonware/xwnode/strategies/nodes/node_union_find.py +187 -0
  83. exonware/xwnode/strategies/nodes/node_xdata_optimized.py +369 -0
  84. exonware/xwnode/strategies/nodes/priority_queue.py +209 -0
  85. exonware/xwnode/strategies/nodes/queue.py +161 -0
  86. exonware/xwnode/strategies/nodes/sparse_matrix.py +206 -0
  87. exonware/xwnode/strategies/nodes/stack.py +152 -0
  88. exonware/xwnode/strategies/nodes/trie.py +274 -0
  89. exonware/xwnode/strategies/nodes/union_find.py +283 -0
  90. exonware/xwnode/strategies/pattern_detector.py +603 -0
  91. exonware/xwnode/strategies/performance_monitor.py +487 -0
  92. exonware/xwnode/strategies/queries/__init__.py +24 -0
  93. exonware/xwnode/strategies/queries/base.py +236 -0
  94. exonware/xwnode/strategies/queries/cql.py +201 -0
  95. exonware/xwnode/strategies/queries/cypher.py +181 -0
  96. exonware/xwnode/strategies/queries/datalog.py +70 -0
  97. exonware/xwnode/strategies/queries/elastic_dsl.py +70 -0
  98. exonware/xwnode/strategies/queries/eql.py +70 -0
  99. exonware/xwnode/strategies/queries/flux.py +70 -0
  100. exonware/xwnode/strategies/queries/gql.py +70 -0
  101. exonware/xwnode/strategies/queries/graphql.py +240 -0
  102. exonware/xwnode/strategies/queries/gremlin.py +181 -0
  103. exonware/xwnode/strategies/queries/hiveql.py +214 -0
  104. exonware/xwnode/strategies/queries/hql.py +70 -0
  105. exonware/xwnode/strategies/queries/jmespath.py +219 -0
  106. exonware/xwnode/strategies/queries/jq.py +66 -0
  107. exonware/xwnode/strategies/queries/json_query.py +66 -0
  108. exonware/xwnode/strategies/queries/jsoniq.py +248 -0
  109. exonware/xwnode/strategies/queries/kql.py +70 -0
  110. exonware/xwnode/strategies/queries/linq.py +238 -0
  111. exonware/xwnode/strategies/queries/logql.py +70 -0
  112. exonware/xwnode/strategies/queries/mql.py +68 -0
  113. exonware/xwnode/strategies/queries/n1ql.py +210 -0
  114. exonware/xwnode/strategies/queries/partiql.py +70 -0
  115. exonware/xwnode/strategies/queries/pig.py +215 -0
  116. exonware/xwnode/strategies/queries/promql.py +70 -0
  117. exonware/xwnode/strategies/queries/sparql.py +220 -0
  118. exonware/xwnode/strategies/queries/sql.py +275 -0
  119. exonware/xwnode/strategies/queries/xml_query.py +66 -0
  120. exonware/xwnode/strategies/queries/xpath.py +223 -0
  121. exonware/xwnode/strategies/queries/xquery.py +258 -0
  122. exonware/xwnode/strategies/queries/xwnode_executor.py +332 -0
  123. exonware/xwnode/strategies/queries/xwquery_strategy.py +424 -0
  124. exonware/xwnode/strategies/registry.py +604 -0
  125. exonware/xwnode/strategies/simple.py +273 -0
  126. exonware/xwnode/strategies/utils.py +532 -0
  127. exonware/xwnode/types.py +912 -0
  128. exonware/xwnode/version.py +78 -0
  129. exonware_xwnode-0.0.1.12.dist-info/METADATA +169 -0
  130. exonware_xwnode-0.0.1.12.dist-info/RECORD +132 -0
  131. exonware_xwnode-0.0.1.12.dist-info/WHEEL +4 -0
  132. 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.")