haiway 0.21.1__py3-none-any.whl → 0.21.3__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.
- haiway/context/access.py +6 -6
- haiway/state/requirement.py +82 -1
- {haiway-0.21.1.dist-info → haiway-0.21.3.dist-info}/METADATA +1 -1
- {haiway-0.21.1.dist-info → haiway-0.21.3.dist-info}/RECORD +6 -6
- {haiway-0.21.1.dist-info → haiway-0.21.3.dist-info}/WHEEL +0 -0
- {haiway-0.21.1.dist-info → haiway-0.21.3.dist-info}/licenses/LICENSE +0 -0
haiway/context/access.py
CHANGED
@@ -302,7 +302,7 @@ class ctx:
|
|
302
302
|
def scope(
|
303
303
|
label: str,
|
304
304
|
/,
|
305
|
-
*state: State,
|
305
|
+
*state: State | None,
|
306
306
|
disposables: Disposables | Iterable[Disposable] | None = None,
|
307
307
|
task_group: TaskGroup | None = None,
|
308
308
|
observability: Observability | Logger | None = None,
|
@@ -316,7 +316,7 @@ class ctx:
|
|
316
316
|
label: str
|
317
317
|
name of the scope context
|
318
318
|
|
319
|
-
*state: State |
|
319
|
+
*state: State | None
|
320
320
|
state propagated within the scope context, will be merged with current state by\
|
321
321
|
replacing current with provided on conflict.
|
322
322
|
|
@@ -355,14 +355,14 @@ class ctx:
|
|
355
355
|
return ScopeContext(
|
356
356
|
label=label,
|
357
357
|
task_group=task_group,
|
358
|
-
state=state,
|
358
|
+
state=tuple(element for element in state if element is not None),
|
359
359
|
disposables=resolved_disposables,
|
360
360
|
observability=observability,
|
361
361
|
)
|
362
362
|
|
363
363
|
@staticmethod
|
364
364
|
def updated(
|
365
|
-
*state: State,
|
365
|
+
*state: State | None,
|
366
366
|
) -> StateContext:
|
367
367
|
"""
|
368
368
|
Update scope context with given state. When called within an existing context\
|
@@ -370,7 +370,7 @@ class ctx:
|
|
370
370
|
|
371
371
|
Parameters
|
372
372
|
----------
|
373
|
-
*state: State
|
373
|
+
*state: State | None
|
374
374
|
state propagated within the updated scope context, will be merged with current if any\
|
375
375
|
by replacing current with provided on conflict
|
376
376
|
|
@@ -380,7 +380,7 @@ class ctx:
|
|
380
380
|
state part of context object intended to enter context manager with it
|
381
381
|
"""
|
382
382
|
|
383
|
-
return StateContext.updated(state)
|
383
|
+
return StateContext.updated(element for element in state if element is not None)
|
384
384
|
|
385
385
|
@staticmethod
|
386
386
|
def spawn[Result, **Arguments](
|
haiway/state/requirement.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
import re
|
2
|
+
import unicodedata
|
3
|
+
from collections.abc import Callable, Collection, Iterable, Sequence, Set
|
2
4
|
from typing import Any, Literal, Self, cast, final
|
3
5
|
|
4
6
|
from haiway.state.path import AttributePath
|
@@ -66,6 +68,83 @@ class AttributeRequirement[Root]:
|
|
66
68
|
check=check_equal,
|
67
69
|
)
|
68
70
|
|
71
|
+
@classmethod
|
72
|
+
def text_match[Parameter](
|
73
|
+
cls,
|
74
|
+
value: str,
|
75
|
+
/,
|
76
|
+
path: AttributePath[Root, str] | str,
|
77
|
+
) -> Self:
|
78
|
+
"""
|
79
|
+
Create a requirement that performs text matching on an attribute.
|
80
|
+
|
81
|
+
Parameters
|
82
|
+
----------
|
83
|
+
value : str
|
84
|
+
The search term (can contain multiple words separated by spaces/punctuation)
|
85
|
+
path : AttributePath[Root, str] | str
|
86
|
+
The path to the string attribute to search in
|
87
|
+
|
88
|
+
Returns
|
89
|
+
-------
|
90
|
+
Self
|
91
|
+
A new requirement instance
|
92
|
+
|
93
|
+
Raises
|
94
|
+
------
|
95
|
+
AssertionError
|
96
|
+
If path is not an AttributePath
|
97
|
+
"""
|
98
|
+
assert isinstance( # nosec: B101
|
99
|
+
path, AttributePath
|
100
|
+
), "Prepare attribute path by using Self._.path.to.property or explicitly"
|
101
|
+
|
102
|
+
def check_like(root: Root) -> None:
|
103
|
+
checked: Any = cast(AttributePath[Root, str], path)(root)
|
104
|
+
if not isinstance(checked, str):
|
105
|
+
raise ValueError(
|
106
|
+
f"Attribute value must be a string for like operation, got {type(checked)}"
|
107
|
+
f" for '{path.__repr__()}'"
|
108
|
+
)
|
109
|
+
|
110
|
+
# Perform full text search with proper Unicode support and word boundaries
|
111
|
+
def tokenize_text(text: str) -> Sequence[str]:
|
112
|
+
# Normalize and case-fold the text
|
113
|
+
normalized = unicodedata.normalize("NFC", text).casefold()
|
114
|
+
# Split on word boundaries and filter out empty strings
|
115
|
+
# re.UNICODE handles international characters, multiline text works by default
|
116
|
+
tokens = re.findall(r"\b\w+\b", normalized, re.UNICODE)
|
117
|
+
return tokens
|
118
|
+
|
119
|
+
# Tokenize both search terms and target text
|
120
|
+
search_tokens: Sequence[str] = tokenize_text(value)
|
121
|
+
target_tokens: Sequence[str] = tokenize_text(checked)
|
122
|
+
target_tokens_set: Set[str] = set(target_tokens)
|
123
|
+
|
124
|
+
# Check if all search tokens are found as complete words in target text
|
125
|
+
missing_terms = [
|
126
|
+
original_term
|
127
|
+
for original_term, token in zip(
|
128
|
+
value.split(),
|
129
|
+
search_tokens,
|
130
|
+
strict=False,
|
131
|
+
)
|
132
|
+
if token not in target_tokens_set
|
133
|
+
]
|
134
|
+
|
135
|
+
if missing_terms:
|
136
|
+
raise ValueError(
|
137
|
+
f"Text search failed: '{checked}' is not like '{value}'. "
|
138
|
+
f"Missing tokens: {missing_terms} for '{path.__repr__()}'"
|
139
|
+
)
|
140
|
+
|
141
|
+
return cls(
|
142
|
+
path,
|
143
|
+
"like",
|
144
|
+
value,
|
145
|
+
check=check_like,
|
146
|
+
)
|
147
|
+
|
69
148
|
@classmethod
|
70
149
|
def not_equal[Parameter](
|
71
150
|
cls,
|
@@ -266,6 +345,7 @@ class AttributeRequirement[Root]:
|
|
266
345
|
lhs: Any,
|
267
346
|
operator: Literal[
|
268
347
|
"equal",
|
348
|
+
"like",
|
269
349
|
"not_equal",
|
270
350
|
"contains",
|
271
351
|
"contains_any",
|
@@ -298,6 +378,7 @@ class AttributeRequirement[Root]:
|
|
298
378
|
)
|
299
379
|
self.operator: Literal[
|
300
380
|
"equal",
|
381
|
+
"like",
|
301
382
|
"not_equal",
|
302
383
|
"contains",
|
303
384
|
"contains_any",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: haiway
|
3
|
-
Version: 0.21.
|
3
|
+
Version: 0.21.3
|
4
4
|
Summary: Framework for dependency injection and state management within structured concurrency model.
|
5
5
|
Project-URL: Homepage, https://miquido.com
|
6
6
|
Project-URL: Repository, https://github.com/miquido/haiway.git
|
@@ -1,7 +1,7 @@
|
|
1
1
|
haiway/__init__.py,sha256=keuz9FN8VqLamqrzvjK2IAjkdyyFcnboDrB9xkFPgXk,1861
|
2
2
|
haiway/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
haiway/context/__init__.py,sha256=1N_SvdPkTfIZDZybm3y0rY2dGrDLWTm0ryzUz2XD4f8,1174
|
4
|
-
haiway/context/access.py,sha256=
|
4
|
+
haiway/context/access.py,sha256=60guObLq5lYjBxSnT9iaEZI5x35Xen_doxY4oCrbn9Q,21758
|
5
5
|
haiway/context/disposables.py,sha256=0vf6kOZ80o6oa8IuU4xQttqtzMT4ODh33XuDh4SGOnc,4742
|
6
6
|
haiway/context/identifier.py,sha256=dCCwLneXJzH__ZWFlGRUHvoCmbT4lM0QVbyokYIbUHg,5255
|
7
7
|
haiway/context/observability.py,sha256=gLKbMPNvt5ozrfyc4TGahN8A_dFFtyCjUIMZu9_wZHA,23722
|
@@ -22,7 +22,7 @@ haiway/opentelemetry/observability.py,sha256=5fsHsFgjcxUcA0hIOM18lVvVdYSRO91ER52
|
|
22
22
|
haiway/state/__init__.py,sha256=AaMqlMhO4zKS_XNevy3A7BHh5PxmguA-Sk_FnaNDY1Q,355
|
23
23
|
haiway/state/attributes.py,sha256=sububiFP23aBB8RGk6OvTUp7BEY6S0kER_uHC09yins,26733
|
24
24
|
haiway/state/path.py,sha256=bv5MI3HmUyku78k0Sz5lc7Q_Bay53iom1l3AL5KZs-4,32143
|
25
|
-
haiway/state/requirement.py,sha256=
|
25
|
+
haiway/state/requirement.py,sha256=uj-mezofTEPDXUuvlHreIjy5Ya-Hig8TR8VE6R8wdyY,15611
|
26
26
|
haiway/state/structure.py,sha256=KKIId-mrHAzGjYKKlvnlscMijVZVM8nDLnAwCFn1sTc,23259
|
27
27
|
haiway/state/validation.py,sha256=eDOZKRrfd-dmdbqoHcLacdCVKmVCEpwt239EG6ljNF8,23557
|
28
28
|
haiway/types/__init__.py,sha256=jFr5kf36SvVGdgngvik6_HzG8YNa3NVsdDDSqxVuGm4,281
|
@@ -39,7 +39,7 @@ haiway/utils/mimic.py,sha256=xaZiUKp096QFfdSw7cNIKEWt2UIS7vf880KF54gny38,1831
|
|
39
39
|
haiway/utils/noop.py,sha256=U8ocfoCgt-pY0owJDPtrRrj53cabeIXH9qCKWMQnoRk,1336
|
40
40
|
haiway/utils/queue.py,sha256=6v2u3pA6A44IuCCTOjmCt3yLyOcm7PCRnrIGo25j-1o,6402
|
41
41
|
haiway/utils/stream.py,sha256=lXaeveTY0-AYG5xVzcQYaiC6SUD5fUtHoMXiQcrQAAM,5723
|
42
|
-
haiway-0.21.
|
43
|
-
haiway-0.21.
|
44
|
-
haiway-0.21.
|
45
|
-
haiway-0.21.
|
42
|
+
haiway-0.21.3.dist-info/METADATA,sha256=iUkk5Z8qoOqq41SjzBEkBlhoFEeBO_eO6pns1C0W08I,4919
|
43
|
+
haiway-0.21.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
44
|
+
haiway-0.21.3.dist-info/licenses/LICENSE,sha256=3phcpHVNBP8jsi77gOO0E7rgKeDeu99Pi7DSnK9YHoQ,1069
|
45
|
+
haiway-0.21.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|