Skip to content

Commit 9eb270a

Browse files
authored
Merge pull request #730 from ikrakara/patch-6
Create emails_ikranur_kara.py
2 parents a958644 + d36bd09 commit 9eb270a

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎Week05/emails_ikranur_kara.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import re
2+
3+
class Emails(list):
4+
def __init__(self, email_list=None):
5+
if email_list is None:
6+
email_list = []
7+
8+
valid_emails = []
9+
for email in email_list:
10+
self.validate(email)
11+
if email not in valid_emails:
12+
valid_emails.append(email)
13+
14+
super().__init__(valid_emails)
15+
16+
@staticmethod
17+
def validate(email):
18+
if not isinstance(email, str):
19+
raise ValueError("Email must be a string.")
20+
21+
# Basit e-posta doğrulama: kullanıcı_adı@domain.uzantı
22+
pattern = r"^[^@]+@[^@]+\.[^@]+$"
23+
if not re.match(pattern, email):
24+
raise ValueError(f"Invalid email address: {email}")
25+
26+
@property
27+
def data(self):
28+
return list(self)
29+
30+
def __repr__(self):
31+
return f"Emails({super().__repr__()})"
32+
33+
def __str__(self):
34+
return f"Emails: {super().__str__()}"

0 commit comments

Comments
 (0)