otsuvalidator 2.0.2__tar.gz → 2.0.3__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.
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/PKG-INFO +1 -1
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/otsuvalidator/__init__.py +1 -1
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/otsuvalidator/bases.py +23 -12
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/tests/test_validators.py +7 -0
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/LICENSE.txt +0 -0
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/Pipfile +0 -0
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/Pipfile.lock +0 -0
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/README.md +0 -0
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/otsuvalidator/converters.py +0 -0
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/otsuvalidator/py.typed +0 -0
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/otsuvalidator/types.py +0 -0
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/otsuvalidator/validators.py +0 -0
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/pyproject.toml +0 -0
- {otsuvalidator-2.0.2 → otsuvalidator-2.0.3}/tests/test_converters.py +0 -0
|
@@ -88,6 +88,7 @@ class VChain[OutT](Validator[OutT]):
|
|
|
88
88
|
def __init__(self, *validators: Validator[Any], pass_type: Literal["all", "any"] = "any") -> None:
|
|
89
89
|
super().__init__()
|
|
90
90
|
self.validators: tuple[Validator[Any], ...] = validators
|
|
91
|
+
self.__target_loggers = [logging.getLogger(mn) for mn in {v.__module__ for v in validators}]
|
|
91
92
|
self.pass_type: Literal["all", "any"] = pass_type
|
|
92
93
|
|
|
93
94
|
def validate(self, value: Any) -> OutT:
|
|
@@ -97,18 +98,28 @@ class VChain[OutT](Validator[OutT]):
|
|
|
97
98
|
for validator in validators:
|
|
98
99
|
current_value = validator.validate(current_value)
|
|
99
100
|
else:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
for
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
101
|
+
# 複数のバリデータのいずれかが通過すればOKなので途中の検証エラーログを無効化する
|
|
102
|
+
original_levels: dict[logging.Logger, int] = {}
|
|
103
|
+
for tl in self.__target_loggers:
|
|
104
|
+
original_levels[tl] = tl.level
|
|
105
|
+
tl.setLevel(logging.CRITICAL + 1)
|
|
106
|
+
|
|
107
|
+
try:
|
|
108
|
+
passed = False
|
|
109
|
+
exceptions = []
|
|
110
|
+
for validator in validators:
|
|
111
|
+
try:
|
|
112
|
+
tmp = validator.validate(current_value)
|
|
113
|
+
current_value = tmp
|
|
114
|
+
passed = True
|
|
115
|
+
except Exception as ex:
|
|
116
|
+
exceptions.append(ex)
|
|
117
|
+
if not passed:
|
|
118
|
+
logger.error(f"全てのバリデータでの検証に失敗しました: {value}")
|
|
119
|
+
raise ValueError(*exceptions)
|
|
120
|
+
finally:
|
|
121
|
+
for tl, level in original_levels.items():
|
|
122
|
+
tl.setLevel(level)
|
|
112
123
|
return current_value
|
|
113
124
|
|
|
114
125
|
def __or__[NextOutT](self, other: Validator[NextOutT]) -> "VChain[NextOutT]":
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import io
|
|
2
|
+
import logging
|
|
2
3
|
import sys
|
|
3
4
|
import unittest
|
|
4
5
|
from typing import Any
|
|
5
6
|
|
|
6
7
|
from otsuvalidator import VChain, VChoice, VDict, VInt, VList, VNone, VString
|
|
7
8
|
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
logging.basicConfig(
|
|
11
|
+
level=logging.DEBUG,
|
|
12
|
+
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
13
|
+
)
|
|
14
|
+
|
|
8
15
|
|
|
9
16
|
class Student:
|
|
10
17
|
name = VString(min_len=1, max_len=50, checker=str.istitle, pattern=r"^[a-zA-Z]+ [a-zA-Z]+$") # 1~50文字, タイトルケース, 正規表現
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|