Skip to content

Commit 6107052

Browse files
Create emails_mehmet_mert_yigit.py
1 parent 2024d08 commit 6107052

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

‎Week05/emails_mehmet_mert_yigit.py‎

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

0 commit comments

Comments
 (0)