File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import re
2+
3+ from pyvalueobjects .errors .ValueObjectError import ValueObjectError
4+ from pyvalueobjects .strings .non_empty_string import NonEmptyString
5+
6+
7+ class Md5Hash (NonEmptyString ):
8+
9+ __MATCHER = re .compile (r'^[a-fA-F0-9]{32}$' )
10+
11+ def __init__ (self , value : str ):
12+ super ().__init__ (value )
13+
14+ def _validate (self , value : str ):
15+ super ()._validate (value )
16+ try :
17+ is_correct = Md5Hash .__MATCHER .match (value )
18+ if not is_correct :
19+ raise ValueObjectError ('Value must be a valid MD5 hash (32 hexadecimal characters).' )
20+ except ValueError :
21+ raise ValueObjectError ('Value must be a valid MD5 hash (32 hexadecimal characters).' )
Original file line number Diff line number Diff line change 1+ from pyvalueobjects .abstract .nullablevalueobject import build_nullable
2+ from pyvalueobjects .security .md5_hash import Md5Hash
3+
4+ _nullable_cls = build_nullable (Md5Hash )
5+
6+
7+ class NullableMd5Hash (_nullable_cls ):
8+
9+ def __init__ (self , value : str = None ):
10+ super ().__init__ (value )
You can’t perform that action at this time.
0 commit comments