vtjson 2.2.3__py3-none-any.whl → 2.2.4__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.
- vtjson/vtjson.py +68 -44
- {vtjson-2.2.3.dist-info → vtjson-2.2.4.dist-info}/METADATA +1 -1
- vtjson-2.2.4.dist-info/RECORD +9 -0
- vtjson-2.2.3.dist-info/RECORD +0 -9
- {vtjson-2.2.3.dist-info → vtjson-2.2.4.dist-info}/AUTHORS +0 -0
- {vtjson-2.2.3.dist-info → vtjson-2.2.4.dist-info}/LICENSE +0 -0
- {vtjson-2.2.3.dist-info → vtjson-2.2.4.dist-info}/WHEEL +0 -0
- {vtjson-2.2.3.dist-info → vtjson-2.2.4.dist-info}/top_level.txt +0 -0
vtjson/vtjson.py
CHANGED
|
@@ -204,7 +204,7 @@ class SchemaError(Exception):
|
|
|
204
204
|
pass
|
|
205
205
|
|
|
206
206
|
|
|
207
|
-
__version__ = "2.2.
|
|
207
|
+
__version__ = "2.2.4"
|
|
208
208
|
|
|
209
209
|
|
|
210
210
|
@dataclass
|
|
@@ -728,29 +728,29 @@ class set_label(wrapper):
|
|
|
728
728
|
)
|
|
729
729
|
|
|
730
730
|
|
|
731
|
-
class
|
|
731
|
+
class _quote(compiled_schema):
|
|
732
|
+
|
|
733
|
+
def __init__(self, schema: object) -> None:
|
|
734
|
+
setattr(self, "__validate__", _const(schema, strict_eq=True).__validate__)
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
class quote(wrapper):
|
|
732
738
|
"""
|
|
733
739
|
An object matches the schema `quote(schema)` if it is equal to `schema`.
|
|
734
740
|
For example the schema `str` matches strings but the schema `quote(str)`
|
|
735
741
|
matches the object `str`.
|
|
736
742
|
"""
|
|
737
743
|
|
|
738
|
-
schema:
|
|
744
|
+
schema: object
|
|
739
745
|
|
|
740
746
|
def __init__(self, schema: object) -> None:
|
|
741
747
|
"""
|
|
742
748
|
:param schema: the schema to be quoted
|
|
743
749
|
"""
|
|
744
|
-
self.schema =
|
|
750
|
+
self.schema = schema
|
|
745
751
|
|
|
746
|
-
def
|
|
747
|
-
self
|
|
748
|
-
obj: object,
|
|
749
|
-
name: str = "object",
|
|
750
|
-
strict: bool = True,
|
|
751
|
-
subs: Mapping[str, object] = {},
|
|
752
|
-
) -> str:
|
|
753
|
-
return self.schema.__validate__(obj, name=name, strict=strict, subs=subs)
|
|
752
|
+
def __compile__(self, _deferred_compiles: _mapping | None = None) -> _quote:
|
|
753
|
+
return _quote(self.schema)
|
|
754
754
|
|
|
755
755
|
|
|
756
756
|
class _set_name(compiled_schema):
|
|
@@ -806,6 +806,10 @@ class set_name(wrapper):
|
|
|
806
806
|
"""
|
|
807
807
|
if not isinstance(name, str):
|
|
808
808
|
raise SchemaError(f"The name {_c(name)} is not a string")
|
|
809
|
+
if not isinstance(reason, bool):
|
|
810
|
+
raise SchemaError(
|
|
811
|
+
f"The parameter 'reason' (value:{repr(reason)}) is not a boolean"
|
|
812
|
+
)
|
|
809
813
|
self.schema = schema
|
|
810
814
|
self.name = name
|
|
811
815
|
self.reason = reason
|
|
@@ -2201,12 +2205,13 @@ class _fields(compiled_schema):
|
|
|
2201
2205
|
|
|
2202
2206
|
def __init__(
|
|
2203
2207
|
self,
|
|
2204
|
-
d: Mapping[
|
|
2208
|
+
d: Mapping[StringKeyType, object],
|
|
2205
2209
|
_deferred_compiles: _mapping | None = None,
|
|
2206
2210
|
) -> None:
|
|
2207
2211
|
self.d = {}
|
|
2208
2212
|
for k, v in d.items():
|
|
2209
|
-
|
|
2213
|
+
key_ = _canonize_key(k)
|
|
2214
|
+
self.d[key_] = _compile(v, _deferred_compiles=_deferred_compiles)
|
|
2210
2215
|
|
|
2211
2216
|
def __validate__(
|
|
2212
2217
|
self,
|
|
@@ -2236,14 +2241,14 @@ class _fields(compiled_schema):
|
|
|
2236
2241
|
return ""
|
|
2237
2242
|
|
|
2238
2243
|
|
|
2239
|
-
class fields(wrapper):
|
|
2244
|
+
class fields(wrapper, Generic[StringKeyType]):
|
|
2240
2245
|
"""
|
|
2241
2246
|
Matches Python objects with attributes `field1, field2, ..., fieldN` whose
|
|
2242
2247
|
corresponding values should validate against `schema1, schema2, ...,
|
|
2243
2248
|
schemaN` respectively.
|
|
2244
2249
|
"""
|
|
2245
2250
|
|
|
2246
|
-
d:
|
|
2251
|
+
d: Mapping[StringKeyType, object]
|
|
2247
2252
|
|
|
2248
2253
|
def __init__(self, d: Mapping[StringKeyType, object]) -> None:
|
|
2249
2254
|
"""
|
|
@@ -2252,7 +2257,6 @@ class fields(wrapper):
|
|
|
2252
2257
|
:raises SchemaError: exception thrown when the schema definition is
|
|
2253
2258
|
found to contain an error
|
|
2254
2259
|
"""
|
|
2255
|
-
self.d = {}
|
|
2256
2260
|
if not isinstance(d, Mapping):
|
|
2257
2261
|
raise SchemaError(f"{repr(d)} is not a Mapping")
|
|
2258
2262
|
for k, v in d.items():
|
|
@@ -2261,8 +2265,7 @@ class fields(wrapper):
|
|
|
2261
2265
|
f"key {repr(k)} in {repr(d)} is not an instance of"
|
|
2262
2266
|
" optional_key and not a string"
|
|
2263
2267
|
)
|
|
2264
|
-
|
|
2265
|
-
self.d[key_] = v
|
|
2268
|
+
self.d = d
|
|
2266
2269
|
|
|
2267
2270
|
def __compile__(self, _deferred_compiles: _mapping | None = None) -> _fields:
|
|
2268
2271
|
return _fields(self.d, _deferred_compiles=_deferred_compiles)
|
|
@@ -2684,6 +2687,48 @@ class _set(compiled_schema):
|
|
|
2684
2687
|
return str(self.schema_)
|
|
2685
2688
|
|
|
2686
2689
|
|
|
2690
|
+
class _protocol(compiled_schema):
|
|
2691
|
+
|
|
2692
|
+
def __init__(
|
|
2693
|
+
self,
|
|
2694
|
+
schema: object,
|
|
2695
|
+
dict: bool = False,
|
|
2696
|
+
_deferred_compiles: _mapping | None = None,
|
|
2697
|
+
) -> None:
|
|
2698
|
+
type_hints = _get_type_hints(schema)
|
|
2699
|
+
total = True
|
|
2700
|
+
if hasattr(schema, "__total__") and isinstance(schema.__total__, bool):
|
|
2701
|
+
total = schema.__total__
|
|
2702
|
+
type_dict = _to_dict(type_hints, total=total)
|
|
2703
|
+
if hasattr(schema, "__name__") and isinstance(schema.__name__, str):
|
|
2704
|
+
name = schema.__name__
|
|
2705
|
+
else:
|
|
2706
|
+
name = "schema"
|
|
2707
|
+
|
|
2708
|
+
if not dict:
|
|
2709
|
+
setattr(
|
|
2710
|
+
self,
|
|
2711
|
+
"__validate__",
|
|
2712
|
+
_set_name(
|
|
2713
|
+
fields(type_dict),
|
|
2714
|
+
name,
|
|
2715
|
+
reason=True,
|
|
2716
|
+
_deferred_compiles=_deferred_compiles,
|
|
2717
|
+
).__validate__,
|
|
2718
|
+
)
|
|
2719
|
+
else:
|
|
2720
|
+
setattr(
|
|
2721
|
+
self,
|
|
2722
|
+
"__validate__",
|
|
2723
|
+
_set_name(
|
|
2724
|
+
type_dict,
|
|
2725
|
+
name,
|
|
2726
|
+
reason=True,
|
|
2727
|
+
_deferred_compiles=_deferred_compiles,
|
|
2728
|
+
).__validate__,
|
|
2729
|
+
)
|
|
2730
|
+
|
|
2731
|
+
|
|
2687
2732
|
class protocol(wrapper):
|
|
2688
2733
|
"""
|
|
2689
2734
|
An object matches the schema `protocol(schema, dict=False)` if `schema` is
|
|
@@ -2691,9 +2736,8 @@ class protocol(wrapper):
|
|
|
2691
2736
|
which validate the corresponding fields in the object.
|
|
2692
2737
|
"""
|
|
2693
2738
|
|
|
2694
|
-
|
|
2739
|
+
schema: object
|
|
2695
2740
|
dict: bool
|
|
2696
|
-
__name__: str
|
|
2697
2741
|
|
|
2698
2742
|
def __init__(self, schema: object, dict: bool = False):
|
|
2699
2743
|
"""
|
|
@@ -2706,34 +2750,14 @@ class protocol(wrapper):
|
|
|
2706
2750
|
"""
|
|
2707
2751
|
if not isinstance(dict, bool):
|
|
2708
2752
|
raise SchemaError("bool flag is not a bool")
|
|
2709
|
-
|
|
2753
|
+
|
|
2710
2754
|
self.dict = dict
|
|
2711
|
-
|
|
2712
|
-
if hasattr(schema, "__total__") and isinstance(schema.__total__, bool):
|
|
2713
|
-
total = schema.__total__
|
|
2714
|
-
self.type_dict = _to_dict(type_hints, total=total)
|
|
2715
|
-
if hasattr(schema, "__name__") and isinstance(schema.__name__, str):
|
|
2716
|
-
self.__name__ = schema.__name__
|
|
2717
|
-
else:
|
|
2718
|
-
self.__name__ = "schema"
|
|
2755
|
+
self.schema = schema
|
|
2719
2756
|
|
|
2720
2757
|
def __compile__(
|
|
2721
2758
|
self, _deferred_compiles: _mapping | None = None
|
|
2722
2759
|
) -> compiled_schema:
|
|
2723
|
-
|
|
2724
|
-
return _set_name(
|
|
2725
|
-
fields(self.type_dict),
|
|
2726
|
-
self.__name__,
|
|
2727
|
-
reason=True,
|
|
2728
|
-
_deferred_compiles=_deferred_compiles,
|
|
2729
|
-
)
|
|
2730
|
-
else:
|
|
2731
|
-
return _set_name(
|
|
2732
|
-
dict(self.type_dict),
|
|
2733
|
-
self.__name__,
|
|
2734
|
-
reason=True,
|
|
2735
|
-
_deferred_compiles=_deferred_compiles,
|
|
2736
|
-
)
|
|
2760
|
+
return _protocol(self.schema, self.dict)
|
|
2737
2761
|
|
|
2738
2762
|
|
|
2739
2763
|
class _Literal(compiled_schema):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vtjson
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.4
|
|
4
4
|
Summary: An easy to use validation library compatible with Python type annotations
|
|
5
5
|
Author-email: Michel Van den Bergh <michel.vandenbergh@uhasselt.be>
|
|
6
6
|
Project-URL: Homepage, https://github.com/vdbergh/vtjson
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
vtjson/__init__.py,sha256=oLX4JH6_R7dYtTiGfBG3pQGR21IArspifdmZilbuGOw,68
|
|
2
|
+
vtjson/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
vtjson/vtjson.py,sha256=-9xIldrpAY6Pf2PDtP9C5d81qb_9cRe4caxZ_Mk9Lj8,86872
|
|
4
|
+
vtjson-2.2.4.dist-info/AUTHORS,sha256=qmxaXxaIO-YPNHJAZ0dcCrnPCs1x9ocbtMksiy4i80M,21
|
|
5
|
+
vtjson-2.2.4.dist-info/LICENSE,sha256=n7xW-zX8xBLHzCdqWIMRuMzBD_ACLcNCwio0LEkKt1o,1077
|
|
6
|
+
vtjson-2.2.4.dist-info/METADATA,sha256=6xmw9KzIW_gMfBAcRJXJlGDfIjv1UxhPJBgmDxCX5Z4,3958
|
|
7
|
+
vtjson-2.2.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
8
|
+
vtjson-2.2.4.dist-info/top_level.txt,sha256=9DlSF3l63igcvnYPcj117F2hzOW4Nx0N-JBoW3jjBZM,7
|
|
9
|
+
vtjson-2.2.4.dist-info/RECORD,,
|
vtjson-2.2.3.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
vtjson/__init__.py,sha256=oLX4JH6_R7dYtTiGfBG3pQGR21IArspifdmZilbuGOw,68
|
|
2
|
-
vtjson/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
vtjson/vtjson.py,sha256=fH8mrDASyEATdvx_ZRNUG5iuMrmLNu-vYw6vrVGXZ1k,86316
|
|
4
|
-
vtjson-2.2.3.dist-info/AUTHORS,sha256=qmxaXxaIO-YPNHJAZ0dcCrnPCs1x9ocbtMksiy4i80M,21
|
|
5
|
-
vtjson-2.2.3.dist-info/LICENSE,sha256=n7xW-zX8xBLHzCdqWIMRuMzBD_ACLcNCwio0LEkKt1o,1077
|
|
6
|
-
vtjson-2.2.3.dist-info/METADATA,sha256=Tljh-yBYXaG0hkFR8n4Yu-gkn_YIhcU5iVvL21JUdAg,3958
|
|
7
|
-
vtjson-2.2.3.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
8
|
-
vtjson-2.2.3.dist-info/top_level.txt,sha256=9DlSF3l63igcvnYPcj117F2hzOW4Nx0N-JBoW3jjBZM,7
|
|
9
|
-
vtjson-2.2.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|