vtjson 2.2.5__tar.gz → 2.2.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vtjson
3
- Version: 2.2.5
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
@@ -204,7 +204,7 @@ class SchemaError(Exception):
204
204
  pass
205
205
 
206
206
 
207
- __version__ = "2.2.5"
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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vtjson
3
- Version: 2.2.5
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
@@ -96,6 +96,7 @@ from vtjson import (
96
96
  protocol,
97
97
  quote,
98
98
  regex,
99
+ regex_pattern,
99
100
  safe_cast,
100
101
  set_label,
101
102
  set_name,
@@ -1844,6 +1845,17 @@ class TestValidation(unittest.TestCase):
1844
1845
  validate(schema, object_)
1845
1846
  show(mc)
1846
1847
 
1848
+ def test_regex_pattern(self) -> None:
1849
+ schema: object
1850
+ object_: object
1851
+ schema = regex_pattern
1852
+ with self.assertRaises(ValidationError) as mc:
1853
+ object_ = "(("
1854
+ validate(schema, object_)
1855
+ show(mc)
1856
+ object_ = ".*"
1857
+ validate(schema, object_)
1858
+
1847
1859
  def test_truncation(self) -> None:
1848
1860
  schema: object
1849
1861
  object_: object
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes