vtjson 2.2.4__py3-none-any.whl → 2.2.6__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 CHANGED
@@ -204,7 +204,7 @@ class SchemaError(Exception):
204
204
  pass
205
205
 
206
206
 
207
- __version__ = "2.2.4"
207
+ __version__ = "2.2.6"
208
208
 
209
209
 
210
210
  @dataclass
@@ -1746,6 +1746,32 @@ class ip_address(compiled_schema):
1746
1746
  return ""
1747
1747
 
1748
1748
 
1749
+ class regex_pattern(compiled_schema):
1750
+ """
1751
+ Matches valid regular expression patterns
1752
+ """
1753
+
1754
+ __name__: str
1755
+
1756
+ def __init__(self) -> None:
1757
+ self.__name__ = "regex_pattern"
1758
+
1759
+ def __validate__(
1760
+ self,
1761
+ obj: object,
1762
+ name: str = "object",
1763
+ strict: bool = True,
1764
+ subs: Mapping[str, object] = {},
1765
+ ) -> str:
1766
+ if not isinstance(obj, str):
1767
+ return _wrong_type_message(obj, name, self.__name__)
1768
+ try:
1769
+ re.compile(obj)
1770
+ except re.error as e:
1771
+ return _wrong_type_message(obj, name, self.__name__, explanation=str(e))
1772
+ return ""
1773
+
1774
+
1749
1775
  class url(compiled_schema):
1750
1776
  """
1751
1777
  Matches valid urls.
@@ -2175,6 +2201,7 @@ class _cond(compiled_schema):
2175
2201
 
2176
2202
  class cond(wrapper):
2177
2203
  """
2204
+ Args is a list of tuples `(if_schema, then_schema)`.
2178
2205
  An object is successively validated against `if_schema1`, `if_schema2`,
2179
2206
  ... until a validation succeeds. When this happens the object should match
2180
2207
  the corresponding `then_schema`. If no `if_schema` succeeds then the
@@ -2243,8 +2270,9 @@ class _fields(compiled_schema):
2243
2270
 
2244
2271
  class fields(wrapper, Generic[StringKeyType]):
2245
2272
  """
2246
- Matches Python objects with attributes `field1, field2, ..., fieldN` whose
2247
- corresponding values should validate against `schema1, schema2, ...,
2273
+ `d` is a dictionary `{"field1": schema1, ...}`.
2274
+ This matches Python objects with attributes `field1, field2, ..., fieldN`
2275
+ whose corresponding values should validate against `schema1, schema2, ...,
2248
2276
  schemaN` respectively.
2249
2277
  """
2250
2278
 
@@ -2306,16 +2334,16 @@ class _filter(compiled_schema):
2306
2334
  obj = self.filter(obj)
2307
2335
  except Exception as e:
2308
2336
  return (
2309
- f"Applying {self.filter_name} to {name} "
2337
+ f"Applying {repr(self.filter_name)} to {name} "
2310
2338
  f"(value: {_c(obj)}) failed: {str(e)}"
2311
2339
  )
2312
2340
  name = f"{self.filter_name}({name})"
2313
- return self.schema.__validate__(obj, name="object", strict=strict, subs=subs)
2341
+ return self.schema.__validate__(obj, name=name, strict=strict, subs=subs)
2314
2342
 
2315
2343
 
2316
2344
  class filter(wrapper):
2317
2345
  """
2318
- Applies `callable` to the object and validates the result with `schema`.
2346
+ Applies `filter` to the object and validates the result with `schema`.
2319
2347
  If the callable throws an exception then validation fails.
2320
2348
  """
2321
2349
 
@@ -2751,6 +2779,9 @@ class protocol(wrapper):
2751
2779
  if not isinstance(dict, bool):
2752
2780
  raise SchemaError("bool flag is not a bool")
2753
2781
 
2782
+ if not hasattr(schema, "__annotations__"):
2783
+ raise SchemaError("schema does not have type annotations")
2784
+
2754
2785
  self.dict = dict
2755
2786
  self.schema = schema
2756
2787
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: vtjson
3
- Version: 2.2.4
3
+ Version: 2.2.6
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
@@ -17,6 +17,7 @@ Requires-Dist: email_validator
17
17
  Requires-Dist: idna
18
18
  Requires-Dist: python-magic
19
19
  Requires-Dist: typing_extensions
20
+ Dynamic: license-file
20
21
 
21
22
  # vtjson
22
23
 
@@ -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=yUD2ojGUUlDZ-KVF5Tzhle6VRoMZx8HVODhWMFFJrZc,87751
4
+ vtjson-2.2.6.dist-info/licenses/AUTHORS,sha256=qmxaXxaIO-YPNHJAZ0dcCrnPCs1x9ocbtMksiy4i80M,21
5
+ vtjson-2.2.6.dist-info/licenses/LICENSE,sha256=n7xW-zX8xBLHzCdqWIMRuMzBD_ACLcNCwio0LEkKt1o,1077
6
+ vtjson-2.2.6.dist-info/METADATA,sha256=yHpR0TUruUh51sZEtYuCveijFPlTtB-ju2WfYYRXR-g,3980
7
+ vtjson-2.2.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ vtjson-2.2.6.dist-info/top_level.txt,sha256=9DlSF3l63igcvnYPcj117F2hzOW4Nx0N-JBoW3jjBZM,7
9
+ vtjson-2.2.6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -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=-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,,