value-object-pattern 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. value_object_pattern/__init__.py +10 -0
  2. value_object_pattern/decorators/__init__.py +7 -0
  3. value_object_pattern/decorators/value_object_process.py +83 -0
  4. value_object_pattern/decorators/value_object_validation.py +78 -0
  5. value_object_pattern/models/__init__.py +3 -0
  6. value_object_pattern/models/value_object.py +383 -0
  7. value_object_pattern/py.typed +0 -0
  8. value_object_pattern/usables/__init__.py +54 -0
  9. value_object_pattern/usables/dates/__init__.py +9 -0
  10. value_object_pattern/usables/dates/date/__init__.py +7 -0
  11. value_object_pattern/usables/dates/date/date_value_object.py +162 -0
  12. value_object_pattern/usables/dates/date/string_date_value_object.py +201 -0
  13. value_object_pattern/usables/dates/datetime/__init__.py +7 -0
  14. value_object_pattern/usables/dates/datetime/datetime_value_object.py +193 -0
  15. value_object_pattern/usables/dates/datetime/string_datetime_value_object.py +237 -0
  16. value_object_pattern/usables/identifiers/__init__.py +7 -0
  17. value_object_pattern/usables/identifiers/country_ids/__init__.py +3 -0
  18. value_object_pattern/usables/identifiers/country_ids/spain/__init__.py +3 -0
  19. value_object_pattern/usables/identifiers/country_ids/spain/dni_value_object.py +63 -0
  20. value_object_pattern/usables/identifiers/string_uuid_value_object.py +56 -0
  21. value_object_pattern/usables/identifiers/uuid_value_object.py +40 -0
  22. value_object_pattern/usables/internet/__init__.py +38 -0
  23. value_object_pattern/usables/internet/api_keys/__init__.py +13 -0
  24. value_object_pattern/usables/internet/api_keys/aws_access_key_id_value_object.py +40 -0
  25. value_object_pattern/usables/internet/api_keys/aws_secret_access_key_value_object.py +40 -0
  26. value_object_pattern/usables/internet/api_keys/github_personal_access_token_value_object.py +41 -0
  27. value_object_pattern/usables/internet/api_keys/openai_api_key_value_object.py +40 -0
  28. value_object_pattern/usables/internet/api_keys/resend_api_key_value_object.py +40 -0
  29. value_object_pattern/usables/internet/aws_cloud_region_value_object.py +77 -0
  30. value_object_pattern/usables/internet/domain_value_object.py +149 -0
  31. value_object_pattern/usables/internet/host_value_object.py +143 -0
  32. value_object_pattern/usables/internet/ipv4_address_value_object.py +305 -0
  33. value_object_pattern/usables/internet/ipv4_network_value_object.py +165 -0
  34. value_object_pattern/usables/internet/ipv6_address_value_object.py +288 -0
  35. value_object_pattern/usables/internet/ipv6_network_value_object.py +145 -0
  36. value_object_pattern/usables/internet/mac_address_value_object.py +390 -0
  37. value_object_pattern/usables/internet/port_value_object.py +682 -0
  38. value_object_pattern/usables/internet/uri/__init__.py +11 -0
  39. value_object_pattern/usables/internet/uri/http_https_url_value_object.py +39 -0
  40. value_object_pattern/usables/internet/uri/http_url_value_object.py +39 -0
  41. value_object_pattern/usables/internet/uri/https_url_value_object.py +39 -0
  42. value_object_pattern/usables/internet/uri/url_value_object.py +396 -0
  43. value_object_pattern/usables/primitives/__init__.py +45 -0
  44. value_object_pattern/usables/primitives/boolean/__init__.py +9 -0
  45. value_object_pattern/usables/primitives/boolean/boolean_value_object.py +36 -0
  46. value_object_pattern/usables/primitives/boolean/false_value_object.py +37 -0
  47. value_object_pattern/usables/primitives/boolean/true_value_object.py +37 -0
  48. value_object_pattern/usables/primitives/bytes/__init__.py +3 -0
  49. value_object_pattern/usables/primitives/bytes/bytes_value_object.py +36 -0
  50. value_object_pattern/usables/primitives/float/__init__.py +9 -0
  51. value_object_pattern/usables/primitives/float/float_value_object.py +36 -0
  52. value_object_pattern/usables/primitives/float/negative_float_value_object.py +37 -0
  53. value_object_pattern/usables/primitives/float/positive_float_value_object.py +37 -0
  54. value_object_pattern/usables/primitives/integer/__init__.py +13 -0
  55. value_object_pattern/usables/primitives/integer/even_integer_value_object.py +37 -0
  56. value_object_pattern/usables/primitives/integer/integer_value_object.py +36 -0
  57. value_object_pattern/usables/primitives/integer/negative_integer_value_object.py +37 -0
  58. value_object_pattern/usables/primitives/integer/odd_integer_value_object.py +37 -0
  59. value_object_pattern/usables/primitives/integer/positive_integer_value_object.py +37 -0
  60. value_object_pattern/usables/primitives/string/__init__.py +21 -0
  61. value_object_pattern/usables/primitives/string/alpha_value_object.py +37 -0
  62. value_object_pattern/usables/primitives/string/alphanumeric_value_object.py +37 -0
  63. value_object_pattern/usables/primitives/string/digit_value_object.py +37 -0
  64. value_object_pattern/usables/primitives/string/lowercase_string_value_object.py +37 -0
  65. value_object_pattern/usables/primitives/string/non_empty_string_value_object.py +37 -0
  66. value_object_pattern/usables/primitives/string/printable_string_value_object.py +37 -0
  67. value_object_pattern/usables/primitives/string/string_value_object.py +36 -0
  68. value_object_pattern/usables/primitives/string/trimmed_string_value_object.py +37 -0
  69. value_object_pattern/usables/primitives/string/uppercase_string_value_object.py +37 -0
  70. value_object_pattern-0.1.0.dist-info/METADATA +95 -0
  71. value_object_pattern-0.1.0.dist-info/RECORD +73 -0
  72. value_object_pattern-0.1.0.dist-info/WHEEL +4 -0
  73. value_object_pattern-0.1.0.dist-info/licenses/LICENSE.md +21 -0
@@ -0,0 +1,36 @@
1
+ """
2
+ BytesValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+ from value_object_pattern.models import ValueObject
7
+
8
+
9
+ class BytesValueObject(ValueObject[bytes]):
10
+ """
11
+ BytesValueObject value object ensures the provided value is bytes.
12
+
13
+ Example:
14
+ ```python
15
+ from value_object_pattern.usables import BytesValueObject
16
+
17
+ bytes_ = BytesValueObject(value=b'aad30be7ce99fb0fe411')
18
+
19
+ print(repr(bytes_))
20
+ # >>> BytesValueObject(value=b'aad30be7ce99fb0fe411')
21
+ ```
22
+ """
23
+
24
+ @validation(order=0)
25
+ def _ensure_value_is_bytes(self, value: bytes) -> None:
26
+ """
27
+ Ensures the value object `value` is bytes.
28
+
29
+ Args:
30
+ value (bytes): The provided value.
31
+
32
+ Raises:
33
+ TypeError: If the `value` is not bytes.
34
+ """
35
+ if type(value) is not bytes:
36
+ raise TypeError(f'BytesValueObject value <<<{str(object=value)}>>> must be bytes. Got <<<{type(value).__name__}>>> type.') # noqa: E501 # fmt: skip
@@ -0,0 +1,9 @@
1
+ from .float_value_object import FloatValueObject
2
+ from .negative_float_value_object import NegativeFloatValueObject
3
+ from .positive_float_value_object import PositiveFloatValueObject
4
+
5
+ __all__ = (
6
+ 'FloatValueObject',
7
+ 'NegativeFloatValueObject',
8
+ 'PositiveFloatValueObject',
9
+ )
@@ -0,0 +1,36 @@
1
+ """
2
+ FloatValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+ from value_object_pattern.models import ValueObject
7
+
8
+
9
+ class FloatValueObject(ValueObject[float]):
10
+ """
11
+ FloatValueObject value object ensures the provided value is a float.
12
+
13
+ Example:
14
+ ```python
15
+ from value_object_pattern.usables import FloatValueObject
16
+
17
+ float_ = FloatValueObject(value=0.5)
18
+
19
+ print(repr(float_))
20
+ # >>> FloatValueObject(value=0.5)
21
+ ```
22
+ """
23
+
24
+ @validation(order=0)
25
+ def _ensure_value_is_float(self, value: float) -> None:
26
+ """
27
+ Ensures the value object `value` is a float.
28
+
29
+ Args:
30
+ value (float): The provided value.
31
+
32
+ Raises:
33
+ TypeError: If the `value` is not a float.
34
+ """
35
+ if type(value) is not float:
36
+ raise TypeError(f'FloatValueObject value <<<{value}>>> must be a float. Got <<<{type(value).__name__}>>> type.') # noqa: E501 # fmt: skip
@@ -0,0 +1,37 @@
1
+ """
2
+ NegativeFloatValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .float_value_object import FloatValueObject
8
+
9
+
10
+ class NegativeFloatValueObject(FloatValueObject):
11
+ """
12
+ NegativeFloatValueObject value object ensures the provided value is a negative float.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import FloatValueObject
17
+
18
+ float_ = FloatValueObject(value=-0.5)
19
+
20
+ print(repr(float_))
21
+ # >>> FloatValueObject(value=-0.5)
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_negative_float(self, value: float) -> None:
27
+ """
28
+ Ensures the value object `value` is a negative float.
29
+
30
+ Args:
31
+ value (float): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is not a negative float.
35
+ """
36
+ if value >= 0:
37
+ raise ValueError(f'NegativeFloatValueObject value <<<{value}>>> must be a negative float.')
@@ -0,0 +1,37 @@
1
+ """
2
+ PositiveFloatValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .float_value_object import FloatValueObject
8
+
9
+
10
+ class PositiveFloatValueObject(FloatValueObject):
11
+ """
12
+ PositiveFloatValueObject value object ensures the provided value is a positive float.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import FloatValueObject
17
+
18
+ float_ = FloatValueObject(value=0.5)
19
+
20
+ print(repr(float_))
21
+ # >>> FloatValueObject(value=0.5)
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_positive_float(self, value: float) -> None:
27
+ """
28
+ Ensures the value object `value` is a positive float.
29
+
30
+ Args:
31
+ value (float): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is not a positive float.
35
+ """
36
+ if value <= 0:
37
+ raise ValueError(f'PositiveFloatValueObject value <<<{value}>>> must be a positive float.')
@@ -0,0 +1,13 @@
1
+ from .even_integer_value_object import EvenIntegerValueObject
2
+ from .integer_value_object import IntegerValueObject
3
+ from .negative_integer_value_object import NegativeIntegerValueObject
4
+ from .odd_integer_value_object import OddIntegerValueObject
5
+ from .positive_integer_value_object import PositiveIntegerValueObject
6
+
7
+ __all__ = (
8
+ 'EvenIntegerValueObject',
9
+ 'IntegerValueObject',
10
+ 'NegativeIntegerValueObject',
11
+ 'OddIntegerValueObject',
12
+ 'PositiveIntegerValueObject',
13
+ )
@@ -0,0 +1,37 @@
1
+ """
2
+ EvenIntegerValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .integer_value_object import IntegerValueObject
8
+
9
+
10
+ class EvenIntegerValueObject(IntegerValueObject):
11
+ """
12
+ EvenIntegerValueObject value object ensures the provided value is an even integer.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import EvenIntegerValueObject
17
+
18
+ integer = EvenIntegerValueObject(value=2)
19
+
20
+ print(repr(integer))
21
+ # >>> EvenIntegerValueObject(value=2)
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_even_number(self, value: int) -> None:
27
+ """
28
+ Ensures the value object `value` is an even number.
29
+
30
+ Args:
31
+ value (int): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is not an even number.
35
+ """
36
+ if value % 2 != 0:
37
+ raise ValueError(f'EvenIntegerValueObject value <<<{value}>>> must be an even number.')
@@ -0,0 +1,36 @@
1
+ """
2
+ IntegerValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+ from value_object_pattern.models import ValueObject
7
+
8
+
9
+ class IntegerValueObject(ValueObject[int]):
10
+ """
11
+ IntegerValueObject value object ensures the provided value is an integer.
12
+
13
+ Example:
14
+ ```python
15
+ from value_object_pattern.usables import IntegerValueObject
16
+
17
+ integer = IntegerValueObject(value=1)
18
+
19
+ print(repr(integer))
20
+ # >>> IntegerValueObject(value=1)
21
+ ```
22
+ """
23
+
24
+ @validation(order=0)
25
+ def _ensure_value_is_integer(self, value: int) -> None:
26
+ """
27
+ Ensures the value object `value` is an integer.
28
+
29
+ Args:
30
+ value (int): The provided value.
31
+
32
+ Raises:
33
+ TypeError: If the `value` is not an integer.
34
+ """
35
+ if type(value) is not int:
36
+ raise TypeError(f'IntegerValueObject value <<<{value}>>> must be an integer. Got <<<{type(value).__name__}>>> type.') # noqa: E501 # fmt: skip
@@ -0,0 +1,37 @@
1
+ """
2
+ NegativeIntegerValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .integer_value_object import IntegerValueObject
8
+
9
+
10
+ class NegativeIntegerValueObject(IntegerValueObject):
11
+ """
12
+ NegativeIntegerValueObject value object ensures the provided value is a negative integer.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import IntegerValueObject
17
+
18
+ integer = IntegerValueObject(value=-1)
19
+
20
+ print(repr(integer))
21
+ # >>> IntegerValueObject(value=-1)
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_negative_integer(self, value: int) -> None:
27
+ """
28
+ Ensures the value object `value` is a negative integer.
29
+
30
+ Args:
31
+ value (int): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is not a negative integer.
35
+ """
36
+ if value >= 0:
37
+ raise ValueError(f'NegativeIntegerValueObject value <<<{value}>>> must be a negative integer.')
@@ -0,0 +1,37 @@
1
+ """
2
+ OddIntegerValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .integer_value_object import IntegerValueObject
8
+
9
+
10
+ class OddIntegerValueObject(IntegerValueObject):
11
+ """
12
+ OddIntegerValueObject value object ensures the provided value is an odd integer.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import IntegerValueObject
17
+
18
+ integer = IntegerValueObject(value=1)
19
+
20
+ print(repr(integer))
21
+ # >>> IntegerValueObject(value=1)
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_odd_number(self, value: int) -> None:
27
+ """
28
+ Ensures the value object `value` is an odd number.
29
+
30
+ Args:
31
+ value (int): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is not an odd number.
35
+ """
36
+ if value % 2 == 0:
37
+ raise ValueError(f'OddIntegerValueObject value <<<{value}>>> must be an odd number.')
@@ -0,0 +1,37 @@
1
+ """
2
+ PositiveIntegerValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .integer_value_object import IntegerValueObject
8
+
9
+
10
+ class PositiveIntegerValueObject(IntegerValueObject):
11
+ """
12
+ PositiveIntegerValueObject value object ensures the provided value is a positive integer.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import PositiveIntegerValueObject
17
+
18
+ integer = PositiveIntegerValueObject(value=1)
19
+
20
+ print(repr(integer))
21
+ # >>> PositiveIntegerValueObject(value=1)
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_positive_integer(self, value: int) -> None:
27
+ """
28
+ Ensures the value object `value` is a positive integer.
29
+
30
+ Args:
31
+ value (int): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is not a positive integer.
35
+ """
36
+ if value <= 0:
37
+ raise ValueError(f'PositiveIntegerValueObject value <<<{value}>>> must be a positive integer.')
@@ -0,0 +1,21 @@
1
+ from .alpha_value_object import AlphaStringValueObject
2
+ from .alphanumeric_value_object import AlphanumericStringValueObject
3
+ from .digit_value_object import DigitStringValueObject
4
+ from .lowercase_string_value_object import LowercaseStringValueObject
5
+ from .non_empty_string_value_object import NotEmptyStringValueObject
6
+ from .printable_string_value_object import PrintableStringValueObject
7
+ from .string_value_object import StringValueObject
8
+ from .trimmed_string_value_object import TrimmedStringValueObject
9
+ from .uppercase_string_value_object import UppercaseStringValueObject
10
+
11
+ __all__ = (
12
+ 'AlphaStringValueObject',
13
+ 'AlphanumericStringValueObject',
14
+ 'DigitStringValueObject',
15
+ 'LowercaseStringValueObject',
16
+ 'NotEmptyStringValueObject',
17
+ 'PrintableStringValueObject',
18
+ 'StringValueObject',
19
+ 'TrimmedStringValueObject',
20
+ 'UppercaseStringValueObject',
21
+ )
@@ -0,0 +1,37 @@
1
+ """
2
+ AlphaStringValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .string_value_object import StringValueObject
8
+
9
+
10
+ class AlphaStringValueObject(StringValueObject):
11
+ """
12
+ AlphaStringValueObject value object ensures the provided value is alpha.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import AlphaStringValueObject
17
+
18
+ string = AlphaStringValueObject(value='abcd')
19
+
20
+ print(repr(string))
21
+ # >>> AlphaStringValueObject(value='abcd')
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_alpha(self, value: str) -> None:
27
+ """
28
+ Ensures the value object `value` is alpha.
29
+
30
+ Args:
31
+ value (str): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is not alpha.
35
+ """
36
+ if not value.isalpha():
37
+ raise ValueError(f'AlphaStringValueObject value <<<{value}>>> contains invalid characters. Only alpha characters are allowed.') # noqa: E501 # fmt: skip
@@ -0,0 +1,37 @@
1
+ """
2
+ AlphanumericStringValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .string_value_object import StringValueObject
8
+
9
+
10
+ class AlphanumericStringValueObject(StringValueObject):
11
+ """
12
+ AlphanumericStringValueObject value object ensures the provided value is alphanumeric.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import AlphanumericStringValueObject
17
+
18
+ string = AlphanumericStringValueObject(value='abcd1234')
19
+
20
+ print(repr(string))
21
+ # >>> AlphanumericStringValueObject(value='abcd1234')
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_alphanumeric(self, value: str) -> None:
27
+ """
28
+ Ensures the value object `value` is alphanumeric.
29
+
30
+ Args:
31
+ value (str): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is not alphanumeric.
35
+ """
36
+ if not value.isalnum():
37
+ raise ValueError(f'AlphanumericStringValueObject value <<<{value}>>> contains invalid characters. Only alphanumeric characters are allowed.') # noqa: E501 # fmt: skip
@@ -0,0 +1,37 @@
1
+ """
2
+ DigitStringValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .string_value_object import StringValueObject
8
+
9
+
10
+ class DigitStringValueObject(StringValueObject):
11
+ """
12
+ DigitStringValueObject value object ensures the provided value is digit.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import DigitStringValueObject
17
+
18
+ string = DigitStringValueObject(value='1234')
19
+
20
+ print(repr(string))
21
+ # >>> DigitStringValueObject(value='1234')
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_digit(self, value: str) -> None:
27
+ """
28
+ Ensures the value object `value` is digit.
29
+
30
+ Args:
31
+ value (str): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is not digit.
35
+ """
36
+ if not value.isdigit():
37
+ raise ValueError(f'DigitStringValueObject value <<<{value}>>> contains invalid characters. Only digit characters are allowed.') # noqa: E501 # fmt: skip
@@ -0,0 +1,37 @@
1
+ """
2
+ LowercaseStringValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .string_value_object import StringValueObject
8
+
9
+
10
+ class LowercaseStringValueObject(StringValueObject):
11
+ """
12
+ LowercaseStringValueObject value object ensures the provided value is lowercase.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import LowercaseStringValueObject
17
+
18
+ string = LowercaseStringValueObject(value='abcd1234')
19
+
20
+ print(repr(string))
21
+ # >>> LowercaseStringValueObject(value='abcd1234')
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_lowercase(self, value: str) -> None:
27
+ """
28
+ Ensures the value object `value` is lowercase.
29
+
30
+ Args:
31
+ value (str): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is not lowercase.
35
+ """
36
+ if not value.islower():
37
+ raise ValueError(f'LowercaseStringValueObject value <<<{value}>>> contains uppercase characters. Only lowercase characters are allowed.') # noqa: E501 # fmt: skip
@@ -0,0 +1,37 @@
1
+ """
2
+ NotEmptyStringValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .string_value_object import StringValueObject
8
+
9
+
10
+ class NotEmptyStringValueObject(StringValueObject):
11
+ """
12
+ NotEmptyStringValueObject value object ensures the provided value is not an empty string.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import NotEmptyStringValueObject
17
+
18
+ string = NotEmptyStringValueObject(value='abcd1234')
19
+
20
+ print(repr(string))
21
+ # >>> NotEmptyStringValueObject(value='abcd1234')
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_not_empty_string(self, value: str) -> None:
27
+ """
28
+ Ensures the value object `value` is not an empty string.
29
+
30
+ Args:
31
+ value (str): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is an empty string.
35
+ """
36
+ if not value:
37
+ raise ValueError(f'NotEmptyStringValueObject value <<<{value}>>> is an empty string. Only non-empty strings are allowed.') # noqa: E501 # fmt: skip
@@ -0,0 +1,37 @@
1
+ """
2
+ PrintableStringValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+
7
+ from .string_value_object import StringValueObject
8
+
9
+
10
+ class PrintableStringValueObject(StringValueObject):
11
+ """
12
+ PrintableStringValueObject value object ensures the provided value is printable.
13
+
14
+ Example:
15
+ ```python
16
+ from value_object_pattern.usables import PrintableStringValueObject
17
+
18
+ string = PrintableStringValueObject(value='abcd1234')
19
+
20
+ print(repr(string))
21
+ # >>> PrintableStringValueObject(value='abcd1234')
22
+ ```
23
+ """
24
+
25
+ @validation(order=0)
26
+ def _ensure_value_is_printable(self, value: str) -> None:
27
+ """
28
+ Ensures the value object `value` is printable.
29
+
30
+ Args:
31
+ value (str): The provided value.
32
+
33
+ Raises:
34
+ ValueError: If the `value` is not printable.
35
+ """
36
+ if not value.isprintable():
37
+ raise ValueError(f'PrintableStringValueObject value <<<{value}>>> contains invalid characters. Only printable characters are allowed.') # noqa: E501 # fmt: skip
@@ -0,0 +1,36 @@
1
+ """
2
+ StringValueObject value object.
3
+ """
4
+
5
+ from value_object_pattern.decorators import validation
6
+ from value_object_pattern.models import ValueObject
7
+
8
+
9
+ class StringValueObject(ValueObject[str]):
10
+ """
11
+ StringValueObject value object ensures the provided value is a string.
12
+
13
+ Example:
14
+ ```python
15
+ from value_object_pattern.usables import StringValueObject
16
+
17
+ string = StringValueObject(value='abcd1234')
18
+
19
+ print(repr(string))
20
+ # >>> StringValueObject(value='abcd1234')
21
+ ```
22
+ """
23
+
24
+ @validation(order=0)
25
+ def _ensure_value_is_string(self, value: str) -> None:
26
+ """
27
+ Ensures the value object `value` is a string.
28
+
29
+ Args:
30
+ value (str): The provided value.
31
+
32
+ Raises:
33
+ TypeError: If the `value` is not a string.
34
+ """
35
+ if type(value) is not str:
36
+ raise TypeError(f'StringValueObject value <<<{value}>>> must be a string. Got <<<{type(value).__name__}>>> type.') # noqa: E501 # fmt: skip