22
33from typing_extensions import get_args , get_origin
44
5+ from extended_type .contains_str import ContainsStrType
6+ from extended_type .prefix_str import PrefixStrType
57from extended_type .range_decimal import RangeDecimalType
68from extended_type .range_float import RangeFloatType
79from extended_type .range_int import RangeIntType
810from extended_type .range_numeric import NUMERIC_TYPE , RangeNumericBase
911from extended_type .regex_str import RegexStrType
12+ from extended_type .suffix_str import SuffixStrType
1013
1114
1215class ExtendedTypeValidator :
@@ -18,6 +21,9 @@ def __init__(
1821 ):
1922 self .validators = validators or {
2023 RegexStrType : self ._validate_regex_str ,
24+ PrefixStrType : self ._validate_prefix_str ,
25+ SuffixStrType : self ._validate_suffix_str ,
26+ ContainsStrType : self ._validate_contains_str ,
2127 RangeIntType : lambda value , annotation : self ._validate_number (
2228 cast (RangeNumericBase , RangeIntType ), value , annotation
2329 ),
@@ -54,3 +60,19 @@ def _validate_number(
5460 def _validate_regex_str (self , value : str , annotation : type [str ]):
5561 pattern = RegexStrType .extract_pattern (annotation )
5662 RegexStrType .validate (pattern , value )
63+
64+ def _validate_email_str (self , value : str , _annotation : type [str ]):
65+ EMAIL_PATTERN = "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\ .[a-zA-Z0-9-.]+$"
66+ RegexStrType .validate (EMAIL_PATTERN , value )
67+
68+ def _validate_prefix_str (self , value : str , annotation : type [str ]):
69+ prefix = PrefixStrType .extract_prefix (annotation )
70+ PrefixStrType .validate (prefix , value )
71+
72+ def _validate_suffix_str (self , value : str , annotation : type [str ]):
73+ subfix = SuffixStrType .extract_suffix (annotation )
74+ SuffixStrType .validate (subfix , value )
75+
76+ def _validate_contains_str (self , value : str , annotation : type [str ]):
77+ subset = ContainsStrType .extract_substring (annotation )
78+ ContainsStrType .validate (subset , value )
0 commit comments