From 05fbe8e8599d0e37e57a53725cac3d4e9889b716 Mon Sep 17 00:00:00 2001 From: Faozia Nikiema Date: Wed, 10 Jun 2026 15:21:34 +0200 Subject: [PATCH 1/2] extended type:email --- stricto/__init__.py | 1 + stricto/dict.py | 2 +- stricto/extended/email.py | 27 +++++++++++++++++ stricto/extended/ip_address.py | 1 + stricto/extended/ip_network.py | 1 + stricto/generic.py | 2 +- tests/__init__.py | 1 + tests/test_email.py | 55 ++++++++++++++++++++++++++++++++++ tests/test_error.py | 1 + tests/test_kparse.py | 1 + tests/test_rights.py | 1 - tests/test_toolbox.py | 1 + 12 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 stricto/extended/email.py create mode 100644 tests/test_email.py diff --git a/stricto/__init__.py b/stricto/__init__.py index c2c97d3..3a0d4c7 100644 --- a/stricto/__init__.py +++ b/stricto/__init__.py @@ -35,3 +35,4 @@ from .selector import Selector from .kparse import Kparse from .event import EVENT_MANAGER +from .extended.email import Email diff --git a/stricto/dict.py b/stricto/dict.py index 0a63f7d..3039457 100644 --- a/stricto/dict.py +++ b/stricto/dict.py @@ -456,7 +456,7 @@ def get_selectors( return self # The index_or_slice is actually ignored. - (key, sub_index_or_slice) = sel.pop() + key, sub_index_or_slice = sel.pop() if key in self._keys: v = self.__dict__[key] diff --git a/stricto/extended/email.py b/stricto/extended/email.py new file mode 100644 index 0000000..394cd4b --- /dev/null +++ b/stricto/extended/email.py @@ -0,0 +1,27 @@ +from stricto import Extend, SConstraintError, STypeError +import re + + +class Email(Extend): + def __init__(self, **kwargs): + super().__init__(str, **kwargs) + + def __json_encode__(self): + va = self.get_value() + if va is None: + return None + return str(self.get_value()) + + def __json_decode__(self, value: str): + return value + + def check_constraints(self, value: str): + pattern1 = r"[A-Za-z0-9-.+]+.[A-Za-z0-9-.+]*" + pattern2 = r"[A-Za-z0-9-.+]+.[A-Za-z]+" + result = pattern1 + r"@" + pattern2 + verify = re.match(result, value) + if verify is None: + raise SConstraintError( + '{0}:Must be a email (value="{value}")', self.path_name(), value=value + ) + return True diff --git a/stricto/extended/ip_address.py b/stricto/extended/ip_address.py index 382d28a..2ef47ef 100644 --- a/stricto/extended/ip_address.py +++ b/stricto/extended/ip_address.py @@ -2,6 +2,7 @@ """ Module for ip adresses """ + import ipaddress from stricto.extend import Extend from stricto import STypeError diff --git a/stricto/extended/ip_network.py b/stricto/extended/ip_network.py index 7dde6c5..5ec34fd 100644 --- a/stricto/extended/ip_network.py +++ b/stricto/extended/ip_network.py @@ -2,6 +2,7 @@ """ Module for ip network addresses in CIDR notation """ + import ipaddress from stricto.extend import Extend from stricto import STypeError diff --git a/stricto/generic.py b/stricto/generic.py index 50e9a47..0c12624 100644 --- a/stricto/generic.py +++ b/stricto/generic.py @@ -544,7 +544,7 @@ def select(self, selector_as_string: str) -> Self | None: if sel.empty(): return self - (key, sub_index_or_slice) = sel.pop() + key, sub_index_or_slice = sel.pop() if key == "$": return self.get_root().get_selectors(sub_index_or_slice, sel) diff --git a/tests/__init__.py b/tests/__init__.py index e2b88ef..453be28 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -22,3 +22,4 @@ from .test_selectors import TestSelectors from .test_toolbox import TestToolbox from .test_kparse import TestKparse +from .test_email import TestEmail diff --git a/tests/test_email.py b/tests/test_email.py new file mode 100644 index 0000000..48930e2 --- /dev/null +++ b/tests/test_email.py @@ -0,0 +1,55 @@ +import unittest +import json +from stricto import ( + Email, + SConstraintError, + StrictoEncoder, + Tuple, + List, + SError, + STypeError, +) + + +class TestEmail(unittest.TestCase): + def __init__(self, m): + unittest.TestCase.__init__(self, m) + self.on_change_bool = False + + def test_error_constraint(self): + a = Email() + with self.assertRaises(SConstraintError) as e: + a.set("emelie.com") + self.assertEqual( + e.exception.to_string(), '$:Must be a email (value="emelie.com")' + ) + + def test_json(self): + a = Email() + b = Email() + a.set("papo@pupo_toro.titi.net") + sa = json.dumps(a, cls=StrictoEncoder) + b.set(json.loads(sa)) + self.assertEqual(b, a) + + def test_get_value(self): + a = Email() + b = Email() + a.set("emelie@network.fr") + v = a.get_value() + b.set(v) + self.assertEqual(b, a) + + def test_get_encoded(self): + a = Email() + b = Email() + a.set("fifi.titi@toto23.too.fr") + v = a.get_encoded() + b.set(v) + self.assertEqual(b, a) + + def test_default(self): + a = Email() + self.assertEqual(a.get_encoded(), None) + a = Email(default="toto.tota@testpass_ok.net") + self.assertEqual(a, "toto.tota@testpass_ok.net") diff --git a/tests/test_error.py b/tests/test_error.py index c18008a..62714e5 100755 --- a/tests/test_error.py +++ b/tests/test_error.py @@ -2,6 +2,7 @@ """ test for Errors() """ + import unittest from stricto import StrictoError, STypeError, SError diff --git a/tests/test_kparse.py b/tests/test_kparse.py index 47ed977..f67e5b0 100755 --- a/tests/test_kparse.py +++ b/tests/test_kparse.py @@ -2,6 +2,7 @@ """ test for Kparse() """ + import unittest from typing import Callable diff --git a/tests/test_rights.py b/tests/test_rights.py index 92d4f53..9071442 100755 --- a/tests/test_rights.py +++ b/tests/test_rights.py @@ -8,7 +8,6 @@ from stricto import String, Int, Dict, SRightError, SAttributeError - can_modify_flag = True # pylint: disable=invalid-name diff --git a/tests/test_toolbox.py b/tests/test_toolbox.py index 874ad11..bbd1c0c 100755 --- a/tests/test_toolbox.py +++ b/tests/test_toolbox.py @@ -2,6 +2,7 @@ """ test for toolbox() """ + import unittest from typing import Any, Callable, Self From 54004c83d06c41bf45ade209194f752ce61c83bb Mon Sep 17 00:00:00 2001 From: Faozia Nikiema Date: Wed, 10 Jun 2026 17:00:05 +0200 Subject: [PATCH 2/2] fix(missing function after module pylint) --- stricto/extended/email.py | 8 +++++++- tests/test_email.py | 17 ++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/stricto/extended/email.py b/stricto/extended/email.py index 394cd4b..4cd7ca4 100644 --- a/stricto/extended/email.py +++ b/stricto/extended/email.py @@ -1,12 +1,17 @@ -from stricto import Extend, SConstraintError, STypeError +""" +Module email verify if valid +""" import re +from stricto import Extend, SConstraintError class Email(Extend): + """Extend type that validates and stores an email address.""" def __init__(self, **kwargs): super().__init__(str, **kwargs) def __json_encode__(self): + va = self.get_value() if va is None: return None @@ -16,6 +21,7 @@ def __json_decode__(self, value: str): return value def check_constraints(self, value: str): + pattern1 = r"[A-Za-z0-9-.+]+.[A-Za-z0-9-.+]*" pattern2 = r"[A-Za-z0-9-.+]+.[A-Za-z]+" result = pattern1 + r"@" + pattern2 diff --git a/tests/test_email.py b/tests/test_email.py index 48930e2..34482ec 100644 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -1,22 +1,17 @@ +"""module for a test_email""" import unittest import json -from stricto import ( - Email, - SConstraintError, - StrictoEncoder, - Tuple, - List, - SError, - STypeError, -) +from stricto import Email, SConstraintError, StrictoEncoder class TestEmail(unittest.TestCase): + """test unitaire for a module mail""" def __init__(self, m): unittest.TestCase.__init__(self, m) self.on_change_bool = False def test_error_constraint(self): + """test error constraint""" a = Email() with self.assertRaises(SConstraintError) as e: a.set("emelie.com") @@ -25,6 +20,7 @@ def test_error_constraint(self): ) def test_json(self): + """test a function json""" a = Email() b = Email() a.set("papo@pupo_toro.titi.net") @@ -33,6 +29,7 @@ def test_json(self): self.assertEqual(b, a) def test_get_value(self): + "test value " a = Email() b = Email() a.set("emelie@network.fr") @@ -41,6 +38,7 @@ def test_get_value(self): self.assertEqual(b, a) def test_get_encoded(self): + """test encoded""" a = Email() b = Email() a.set("fifi.titi@toto23.too.fr") @@ -49,6 +47,7 @@ def test_get_encoded(self): self.assertEqual(b, a) def test_default(self): + """test value default""" a = Email() self.assertEqual(a.get_encoded(), None) a = Email(default="toto.tota@testpass_ok.net")