File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ import re
2+
3+
4+ class Emails (list ):
5+ """
6+ A list subclass that stores and validates email addresses.
7+ """
8+
9+ def __init__ (self , data ):
10+ self .validate (data )
11+ # remove duplicates
12+ unique_emails = list (set (data ))
13+ super ().__init__ (unique_emails )
14+ self .data = self # testlerde .data kullanıldığı için
15+
16+ def validate (self , data ):
17+ # check all items are strings
18+ for item in data :
19+ if not isinstance (item , str ):
20+ raise ValueError ("All items must be strings" )
21+
22+ # email regex
23+ email_pattern = re .compile (r"^[^@]+@[^@]+\.[^@]+$" )
24+
25+ for email in data :
26+ if not email_pattern .match (email ):
27+ raise ValueError ("Invalid email address" )
28+
29+ def __repr__ (self ):
30+ return f"{ self .__class__ .__name__ } ({ list (self )} )"
31+
32+ def __str__ (self ):
33+ return ", " .join (self )
You can’t perform that action at this time.
0 commit comments