From 0763e357a2109ead2e3cc24bd4a95564f404ee5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Chy=C5=82a?= Date: Sun, 17 Jun 2018 17:25:44 +0000 Subject: [PATCH] exercise-1.py --- exercise-1.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/exercise-1.py b/exercise-1.py index 1323c1b..651acb6 100644 --- a/exercise-1.py +++ b/exercise-1.py @@ -15,18 +15,24 @@ import unittest -EMAIL_PATTERN = re.compile(r'^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$') +class EMail: + EMAIL_PATTERN = re.compile(r'^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$') + def __init__(self, email): + if self.EMAIL_PATTERN.match(email) is None: + raise ValueError('Invalid email') + else: + self.email = email + + def __str__(self): + return self.email class Person: def __init__(self, first_name, last_name, email): assert isinstance(first_name, str) assert isinstance(last_name, str) assert isinstance(email, str) - - self.first_name = first_name + + self.first_name = first_name self.last_name = last_name - if EMAIL_PATTERN.match(email) is None: - raise ValueError('Invalid email') - else: - self.email = email + self.email = EMail(email)