Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Week05/emails_yunus_dermencioglu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import re


class Emails(list):

def __init__(self, emails):
super().__init__()
self.data = []

for email in emails:
self.validate(email)

if email not in self.data:
self.data.append(email)
super().append(email)

def validate(self, email):
if not isinstance(email, str):
raise ValueError("Email must be a string")

pattern = r"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"

if not re.fullmatch(pattern, email):
raise ValueError("Invalid email address")

return True

def __repr__(self):
return f"Emails({self.data!r})"

def __str__(self):
return str(self.data)
Loading