enforce-rules 3.2.0__tar.gz → 3.2.2__tar.gz
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.
- {enforce_rules-3.2.0/src/enforce_rules.egg-info → enforce_rules-3.2.2}/PKG-INFO +2 -2
- {enforce_rules-3.2.0 → enforce_rules-3.2.2}/README.md +1 -1
- {enforce_rules-3.2.0 → enforce_rules-3.2.2}/pyproject.toml +1 -1
- {enforce_rules-3.2.0 → enforce_rules-3.2.2}/src/enforce_rules/enforce_rules.py +35 -5
- {enforce_rules-3.2.0 → enforce_rules-3.2.2/src/enforce_rules.egg-info}/PKG-INFO +2 -2
- {enforce_rules-3.2.0 → enforce_rules-3.2.2}/LICENSE +0 -0
- {enforce_rules-3.2.0 → enforce_rules-3.2.2}/setup.cfg +0 -0
- {enforce_rules-3.2.0 → enforce_rules-3.2.2}/src/enforce_rules/__init__.py +0 -0
- {enforce_rules-3.2.0 → enforce_rules-3.2.2}/src/enforce_rules.egg-info/SOURCES.txt +0 -0
- {enforce_rules-3.2.0 → enforce_rules-3.2.2}/src/enforce_rules.egg-info/dependency_links.txt +0 -0
- {enforce_rules-3.2.0 → enforce_rules-3.2.2}/src/enforce_rules.egg-info/top_level.txt +0 -0
- {enforce_rules-3.2.0 → enforce_rules-3.2.2}/tests/test_enforce_rules.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: enforce-rules
|
|
3
|
-
Version: 3.2.
|
|
3
|
+
Version: 3.2.2
|
|
4
4
|
Summary: Runtime rule validation for Python using dictionary-based constraints.
|
|
5
5
|
Author: Jake Loepker, Microsoft Copilot (AI Assistant)
|
|
6
6
|
License: BSD 3-Clause License
|
|
@@ -63,7 +63,7 @@ MAJOR: 3
|
|
|
63
63
|
|
|
64
64
|
MINOR: 2
|
|
65
65
|
|
|
66
|
-
PATCH:
|
|
66
|
+
PATCH: 2
|
|
67
67
|
|
|
68
68
|
If you need to catch up, you can see the full version history in the [CHANGELOG](https://github.com/Loepker-James/enforce-rules/blob/main/CHANGELOG.md).
|
|
69
69
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Dict, Callable, Literal, TypeVar
|
|
1
|
+
from typing import Dict, Callable, Literal, TypeVar, TypedDict, TypeAlias
|
|
2
2
|
from collections.abc import Iterable, Sequence, Container
|
|
3
3
|
import re
|
|
4
4
|
from datetime import datetime
|
|
@@ -170,7 +170,37 @@ def _validate_is_password(value: str, rule: bool) -> None:
|
|
|
170
170
|
# VALIDATE() — DEFINED LAST
|
|
171
171
|
# -----------------------------
|
|
172
172
|
T = TypeVar("T")
|
|
173
|
-
|
|
173
|
+
Number: TypeAlias = int | float
|
|
174
|
+
|
|
175
|
+
class ValidateDict(TypedDict, total=False):
|
|
176
|
+
length: int
|
|
177
|
+
min_length: int
|
|
178
|
+
max_length: int
|
|
179
|
+
min: Number
|
|
180
|
+
max: Number
|
|
181
|
+
allowed_values: Iterable
|
|
182
|
+
invariant: bool
|
|
183
|
+
all_same: bool
|
|
184
|
+
all_unique: bool
|
|
185
|
+
non_empty: bool
|
|
186
|
+
no_nulls: bool
|
|
187
|
+
sorted: bool
|
|
188
|
+
increasing: bool
|
|
189
|
+
decreasing: bool
|
|
190
|
+
sum_min: Number
|
|
191
|
+
sum_max: Number
|
|
192
|
+
element_min: Number
|
|
193
|
+
element_max: Number
|
|
194
|
+
regex: str
|
|
195
|
+
regex_flags: object
|
|
196
|
+
must_be_true: Callable[[object], bool]
|
|
197
|
+
before_date: datetime
|
|
198
|
+
after_date: datetime
|
|
199
|
+
piece_color: bool
|
|
200
|
+
piece_type: Literal[1, 2, 3, 4, 5, 6]
|
|
201
|
+
chess_symbol: Literal["p", "n", "b", "r", "q", "k", "P", "N", "B", "R", "Q", "K"]
|
|
202
|
+
|
|
203
|
+
def validate(value: T, rules: ValidateDict) -> T:
|
|
174
204
|
# Do not mutate value
|
|
175
205
|
"""
|
|
176
206
|
Validate a value against a dictionary of rules.
|
|
@@ -237,10 +267,10 @@ def validate(value: T, rules: Dict[str, object]) -> T:
|
|
|
237
267
|
raise ValueError(f"Unknown rule: {key}")
|
|
238
268
|
|
|
239
269
|
return value
|
|
240
|
-
|
|
241
|
-
def is_valid(value: object, rules:
|
|
270
|
+
|
|
271
|
+
def is_valid(value: object, rules: ValidateDict) -> bool:
|
|
242
272
|
try:
|
|
243
273
|
validate(value, rules)
|
|
244
274
|
return True
|
|
245
275
|
except:
|
|
246
|
-
return False
|
|
276
|
+
return False
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: enforce-rules
|
|
3
|
-
Version: 3.2.
|
|
3
|
+
Version: 3.2.2
|
|
4
4
|
Summary: Runtime rule validation for Python using dictionary-based constraints.
|
|
5
5
|
Author: Jake Loepker, Microsoft Copilot (AI Assistant)
|
|
6
6
|
License: BSD 3-Clause License
|
|
@@ -63,7 +63,7 @@ MAJOR: 3
|
|
|
63
63
|
|
|
64
64
|
MINOR: 2
|
|
65
65
|
|
|
66
|
-
PATCH:
|
|
66
|
+
PATCH: 2
|
|
67
67
|
|
|
68
68
|
If you need to catch up, you can see the full version history in the [CHANGELOG](https://github.com/Loepker-James/enforce-rules/blob/main/CHANGELOG.md).
|
|
69
69
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|