File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ import re
2+
3+ class Emails (list ):
4+ def __init__ (self , emails ):
5+ unique_emails = []
6+ if emails :
7+ seen = set ()
8+ for email in emails :
9+ if email not in seen :
10+ unique_emails .append (email )
11+ seen .add (email )
12+
13+ super ().__init__ (unique_emails )
14+
15+ self .data = self
16+
17+
18+ self .validate ()
19+
20+ def validate (self ):
21+
22+ email_pattern = re .compile (r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' )
23+
24+ for email in self :
25+
26+ if not isinstance (email , str ):
27+ raise ValueError ("Emails must be strings" )
28+
29+ if not email_pattern .match (email ):
30+ raise ValueError (f"Invalid email address: { email } " )
31+
32+ def __repr__ (self ):
33+
34+ return f"Emails({ super ().__repr__ ()} )"
35+
36+ def __str__ (self ):
37+
38+ return f"Emails({ super ().__str__ ()} )"
You can’t perform that action at this time.
0 commit comments