From 9a4312f996dee951cbfbd22ff28c138d6edc31dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Balc=C4=B1?= <148548201+MehmetxBalci@users.noreply.github.com> Date: Tue, 3 Nov 2026 16:20:55 +0300 Subject: [PATCH] Add Emails class for email validation and storage --- Week05/emails_mehmet_balci.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Week05/emails_mehmet_balci.py diff --git a/Week05/emails_mehmet_balci.py b/Week05/emails_mehmet_balci.py new file mode 100644 index 00000000..010f9c4c --- /dev/null +++ b/Week05/emails_mehmet_balci.py @@ -0,0 +1,30 @@ +import re + + +class Emails(list): + + EMAIL_PATTERN = re.compile(r"[^@\s]+@[^@\s]+\.[^@\s]+") + + def __init__(self, emails): + super().__init__() + self.validate(emails) + for email in emails: + if email not in self: # tekrar edenleri ekleme + self.append(email) + + @property + def data(self): + return list(self) + + def validate(self, emails): + for email in emails: + if not isinstance(email, str): + raise ValueError(f"{email!r} is not a string") + if not self.EMAIL_PATTERN.fullmatch(email): + raise ValueError(f"{email!r} is not a valid email address") + + def __repr__(self): + return f"Emails({list.__repr__(self)})" + + def __str__(self): + return ", ".join(self)