datavalue 0.1.2__tar.gz → 0.1.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datavalue
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Librería de tipos de datos primitivos y complejos
5
5
  Author: Specter
6
6
  Requires-Python: >=3.10
@@ -0,0 +1,99 @@
1
+ # Library import
2
+ import re
3
+ from typing import Type, Optional, Any, Iterable, Union
4
+ from .. import exceptions
5
+
6
+ # Classes definition
7
+ class PrimitiveData:
8
+ def __init__(self,
9
+ data_type: Type,
10
+ value: Any,
11
+ maximum_length: Optional[int] = None, minimum_length: Optional[int] = None,
12
+ maximum_size: Optional[Union[int, float]] = None, minimum_size: Optional[Union[int, float]] = None,
13
+ possible_values: Optional[Iterable] = None,
14
+ regular_expression: Optional[str] = None,
15
+
16
+ data_class: Optional[bool] = False
17
+ ) -> None:
18
+ # Instance properties assignment
19
+ self.data_type = data_type
20
+ self.value = value
21
+ self.maximum_length = maximum_length; self.minimum_length = minimum_length
22
+ self.maximum_size = maximum_size; self.minimum_size = minimum_size
23
+ self.possible_values = possible_values
24
+ self.regular_expression = regular_expression
25
+ self.data_class = data_class
26
+
27
+ if not self.data_class:
28
+ self.validate()
29
+
30
+ # Private methods
31
+ def __get_length(self) -> Optional[int]:
32
+ if isinstance(self.value, (str, bytes, bytearray)):
33
+ return len(self.value)
34
+ elif isinstance(self.value, (int, float)):
35
+ return len([digit for digit in str(self.value) if digit.isdigit()])
36
+ else:
37
+ return None
38
+
39
+ # Public methods
40
+ def to_dict(self) -> dict:
41
+ return {
42
+ "DATA_TYPE":self.data_type.__name__ if hasattr(self.data_type, '__name__') else str(self.data_type),
43
+ "VALUE":self.value,
44
+ "MAXIMUM_LENGTH":self.maximum_length,
45
+ "MINIMUM_LENGTH":self.minimum_length,
46
+ "MAXIMUM_SIZE":self.maximum_size,
47
+ "MINIMUM_SIZE":self.minimum_size,
48
+ "POSSIBLE_VALUES":self.possible_values if self.possible_values is not None else None,
49
+ "REGULAR_EXPRESSION":self.regular_expression,
50
+ "DATA_CLASS":self.data_class
51
+ }
52
+
53
+ def validate(self) -> bool:
54
+ # Validacion de tipo de dato
55
+ if not isinstance(self.value, self.data_type):
56
+ raise exceptions.DataTypeException(
57
+ f"Incorrect data type.\nExpected: {self.data_type.__name__} - Received: {type(self.value).__name__}"
58
+ )
59
+
60
+ # Validacion de longitud de caracteres (minimo, y maximo)
61
+ if self.minimum_length is not None or self.maximum_length is not None:
62
+ length = self.__get_length()
63
+
64
+ if length is not None:
65
+ if self.minimum_length is not None and length < self.minimum_length:
66
+ raise exceptions.LengthException(f"Character/digit length below the minimum: {length} < {self.minimum_length}")
67
+ elif self.maximum_length is not None and length > self.maximum_length:
68
+ raise exceptions.LengthException(f"Character/digit length above the maximum: {length} > {self.maximum_length}")
69
+
70
+ # Validacion de tamaño (magnitud)
71
+ if self.minimum_size is not None or self.maximum_size is not None:
72
+ if isinstance(self.value, (int, float)):
73
+ if self.minimum_size is not None and self.value < self.minimum_size:
74
+ raise exceptions.SizeException(f"Numerical value below the minimum: {self.value} < {self.minimum_size}")
75
+ if self.maximum_size is not None and self.value > self.maximum_size:
76
+ raise exceptions.SizeException(f"Numerical value above the maximum: {self.value} > {self.maximum_size}")
77
+
78
+ # Validacion de posibles valores (conjunto)
79
+ if self.data_type is bool:
80
+ if self.value not in (True, False):
81
+ raise exceptions.PossibleValueException(
82
+ f"The boolean value has to be True or False: {self.value} != True/False"
83
+ )
84
+ if self.possible_values is not None:
85
+ if self.value not in self.possible_values:
86
+ raise exceptions.PossibleValueException(
87
+ f"The value is not in the possible values set: {self.value} not in {self.possible_values}"
88
+ )
89
+
90
+ # Validacion de expresion regular
91
+ if self.regular_expression is not None:
92
+ if isinstance(self.value, (str, bytes, bytearray)):
93
+ # Soporte para bytes/bytearray convirtiendo el patrón si es necesario
94
+ pattern = self.regular_expression
95
+ if isinstance(self.value, (bytes, bytearray)) and isinstance(pattern, str):
96
+ pattern = pattern.encode()
97
+
98
+ if not re.fullmatch(pattern, self.value):
99
+ raise exceptions.RegularExpressionException(f"The value does not meet the required pattern: {self.regular_expression}")
@@ -0,0 +1,10 @@
1
+ # Classes definition
2
+ # Base exception
3
+ class DataValueException(Exception): pass
4
+
5
+ # Specific exceptions
6
+ class DataTypeException(DataValueException): pass
7
+ class LengthException(DataValueException): pass
8
+ class SizeException(DataValueException): pass
9
+ class PossibleValueException(DataValueException): pass
10
+ class RegularExpressionException(DataValueException): pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datavalue
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Librería de tipos de datos primitivos y complejos
5
5
  Author: Specter
6
6
  Requires-Python: >=3.10
@@ -5,4 +5,7 @@ datavalue.egg-info/PKG-INFO
5
5
  datavalue.egg-info/SOURCES.txt
6
6
  datavalue.egg-info/dependency_links.txt
7
7
  datavalue.egg-info/top_level.txt
8
+ datavalue/classes/__init__.py
9
+ datavalue/classes/primitive_data.py
10
+ datavalue/exceptions/__init__.py
8
11
  tests/test.py
@@ -0,0 +1,4 @@
1
+ datavalue
2
+ dist
3
+ docs
4
+ tests
@@ -3,13 +3,12 @@ requires = ["setuptools>=61.0"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
- name = "datavalue" # Nombre en PyPI
7
- version = "0.1.2"
6
+ name = "datavalue"
7
+ version = "0.1.3"
8
8
  description = "Librería de tipos de datos primitivos y complejos"
9
9
  readme = "README.md"
10
10
  authors = [{ name="Specter" }]
11
11
  requires-python = ">=3.10"
12
12
 
13
13
  [tool.setuptools]
14
- # Esto le dice a Python que el paquete es la carpeta actual
15
- packages = ["datavalue"]
14
+ packages = { find = {} }
@@ -1 +0,0 @@
1
- datavalue
File without changes
File without changes
File without changes