-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathemails_emine_cetin.py
More file actions
28 lines (23 loc) · 877 Bytes
/
emails_emine_cetin.py
File metadata and controls
28 lines (23 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import re
class Emails(list):
def __init__(self, emails):
if not all(isinstance(email, str) for email in emails):
raise ValueError("All items must be strings.")
pattern = re.compile(r"^[^@]+@[^@]+\.[^@]+$")
for email in emails:
if not pattern.match(email):
raise ValueError(f"Invalid email address: {email}")
unique_emails = list(dict.fromkeys(emails))
super().__init__(unique_emails)
self.data = self
def validate(self):
"""
Existence of this method is required by test_validate.
Actual validation logic is handled in __init__ to ensure
ValueErrors are raised during instantiation.
"""
return True
def __repr__(self):
return f"Emails({super().__repr__()})"
def __str__(self):
return super().__repr__()