File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ import re
2+
3+ EMAIL_REGEX = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
4+
5+
6+ class Emails (list ):
7+ @staticmethod
8+ def validate (email_list ):
9+ if not all (isinstance (mail , str ) for mail in email_list ):
10+ raise ValueError ("Emails list can only contain string values." )
11+
12+ for mail in email_list :
13+ if not re .fullmatch (EMAIL_REGEX , mail ):
14+ raise ValueError (f"'{ mail } ' is not a valid email format." )
15+
16+ return list (set (email_list ))
17+
18+ def __init__ (self , initial_emails = None ):
19+ initial_emails = initial_emails or []
20+ clean_list = Emails .validate (initial_emails )
21+ self .data = clean_list
22+ super ().__init__ (clean_list )
23+
24+ def __repr__ (self ):
25+ return f"Emails({ super ().__repr__ ()} )"
26+
27+ def __str__ (self ):
28+ return "\n " .join (self )
You can’t perform that action at this time.
0 commit comments