Skip to content

Commit cc909f1

Browse files
author
Seher Arslanbay
committed
emails seher arslanbay hw
1 parent f67d66b commit cc909f1

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎Week05/emails_seher_arslanbay.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
import re
3+
4+
5+
class Emails(list):
6+
7+
EMAIL_PATTERN = re.compile(r"[^@\s]+@[^@\s]+\.[^@\s]+")
8+
9+
def __init__(self, emails):
10+
super().__init__()
11+
self.validate(emails)
12+
13+
for email in emails:
14+
if email not in self:
15+
self.append(email)
16+
17+
@property
18+
def data(self):
19+
return list(self)
20+
21+
def validate(self, emails):
22+
for email in emails:
23+
if not isinstance(email, str):
24+
raise ValueError("Email must be a string")
25+
26+
if not self.EMAIL_PATTERN.fullmatch(email):
27+
raise ValueError("Invalid email address: " + email)
28+
29+
def __repr__(self):
30+
return f"Emails({list.__repr__(self)})"
31+
32+
def __str__(self):
33+
return ", ".join(self)

0 commit comments

Comments
 (0)