File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ import re
2+
3+ class Emails (list ):
4+ EMAIL_REGEX = re .compile (r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$" )
5+
6+ def __init__ (self , items ):
7+ self ._check (items )
8+ cleaned = self ._unique (items )
9+ super ().__init__ (cleaned )
10+ self .data = cleaned
11+
12+ def _check (self , items ):
13+ if not all (type (x ) is str for x in items ):
14+ raise ValueError ("All items must be strings" )
15+
16+ for mail in items :
17+ if not self .EMAIL_REGEX .fullmatch (mail ):
18+ raise ValueError ("Invalid email address" )
19+
20+ @staticmethod
21+ def _unique (items ):
22+ seen = []
23+ for x in items :
24+ if x not in seen :
25+ seen .append (x )
26+ return seen
27+
28+ def __repr__ (self ):
29+ return f"{ self .__class__ .__name__ } ({ list (self )} )"
30+
31+ def __str__ (self ):
32+ return "\n " .join (self )
You can’t perform that action at this time.
0 commit comments