datavalue 0.1.3__py3-none-any.whl → 0.1.4__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.
- datavalue/classes/primitive_data.py +34 -21
- {datavalue-0.1.3.dist-info → datavalue-0.1.4.dist-info}/METADATA +1 -1
- datavalue-0.1.4.dist-info/RECORD +9 -0
- tests/test.py +60 -2
- datavalue-0.1.3.dist-info/RECORD +0 -9
- {datavalue-0.1.3.dist-info → datavalue-0.1.4.dist-info}/WHEEL +0 -0
- {datavalue-0.1.3.dist-info → datavalue-0.1.4.dist-info}/top_level.txt +0 -0
|
@@ -28,11 +28,16 @@ class PrimitiveData:
|
|
|
28
28
|
self.validate()
|
|
29
29
|
|
|
30
30
|
# Private methods
|
|
31
|
-
def __get_length(self) -> Optional[int]:
|
|
32
|
-
if
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
def __get_length(self, data: Optional[Any] = None) -> Optional[int]:
|
|
32
|
+
if data is None:
|
|
33
|
+
data_objective = self.value
|
|
34
|
+
else:
|
|
35
|
+
data_objective = data
|
|
36
|
+
|
|
37
|
+
if isinstance(data_objective, (str, bytes, bytearray)):
|
|
38
|
+
return len(data_objective)
|
|
39
|
+
elif isinstance(data_objective, (int, float)):
|
|
40
|
+
return len([digit for digit in str(data_objective) if digit.isdigit()])
|
|
36
41
|
else:
|
|
37
42
|
return None
|
|
38
43
|
|
|
@@ -50,16 +55,22 @@ class PrimitiveData:
|
|
|
50
55
|
"DATA_CLASS":self.data_class
|
|
51
56
|
}
|
|
52
57
|
|
|
53
|
-
def validate(self) -> bool:
|
|
58
|
+
def validate(self, data: Optional[Any] = None) -> bool:
|
|
59
|
+
# Define the data to validate
|
|
60
|
+
if data is None:
|
|
61
|
+
data_objective = self.value
|
|
62
|
+
else:
|
|
63
|
+
data_objective = data
|
|
64
|
+
|
|
54
65
|
# Validacion de tipo de dato
|
|
55
|
-
if not isinstance(
|
|
66
|
+
if not isinstance(data_objective, self.data_type):
|
|
56
67
|
raise exceptions.DataTypeException(
|
|
57
|
-
f"Incorrect data type.\nExpected: {self.data_type.__name__} - Received: {type(
|
|
68
|
+
f"Incorrect data type.\nExpected: {self.data_type.__name__} - Received: {type(data_objective).__name__}"
|
|
58
69
|
)
|
|
59
70
|
|
|
60
71
|
# Validacion de longitud de caracteres (minimo, y maximo)
|
|
61
72
|
if self.minimum_length is not None or self.maximum_length is not None:
|
|
62
|
-
length = self.__get_length()
|
|
73
|
+
length = self.__get_length(data_objective)
|
|
63
74
|
|
|
64
75
|
if length is not None:
|
|
65
76
|
if self.minimum_length is not None and length < self.minimum_length:
|
|
@@ -69,31 +80,33 @@ class PrimitiveData:
|
|
|
69
80
|
|
|
70
81
|
# Validacion de tamaño (magnitud)
|
|
71
82
|
if self.minimum_size is not None or self.maximum_size is not None:
|
|
72
|
-
if isinstance(
|
|
73
|
-
if self.minimum_size is not None and
|
|
74
|
-
raise exceptions.SizeException(f"Numerical value below the minimum: {
|
|
75
|
-
if self.maximum_size is not None and
|
|
76
|
-
raise exceptions.SizeException(f"Numerical value above the maximum: {
|
|
83
|
+
if isinstance(data_objective, (int, float)):
|
|
84
|
+
if self.minimum_size is not None and data_objective < self.minimum_size:
|
|
85
|
+
raise exceptions.SizeException(f"Numerical value below the minimum: {data_objective} < {self.minimum_size}")
|
|
86
|
+
if self.maximum_size is not None and data_objective > self.maximum_size:
|
|
87
|
+
raise exceptions.SizeException(f"Numerical value above the maximum: {data_objective} > {self.maximum_size}")
|
|
77
88
|
|
|
78
89
|
# Validacion de posibles valores (conjunto)
|
|
79
90
|
if self.data_type is bool:
|
|
80
|
-
if
|
|
91
|
+
if data_objective not in (True, False):
|
|
81
92
|
raise exceptions.PossibleValueException(
|
|
82
|
-
f"The boolean value has to be True or False: {
|
|
93
|
+
f"The boolean value has to be True or False: {data_objective} != True/False"
|
|
83
94
|
)
|
|
84
95
|
if self.possible_values is not None:
|
|
85
|
-
if
|
|
96
|
+
if data_objective not in self.possible_values:
|
|
86
97
|
raise exceptions.PossibleValueException(
|
|
87
|
-
f"The value is not in the possible values set: {
|
|
98
|
+
f"The value is not in the possible values set: {data_objective} not in {self.possible_values}"
|
|
88
99
|
)
|
|
89
100
|
|
|
90
101
|
# Validacion de expresion regular
|
|
91
102
|
if self.regular_expression is not None:
|
|
92
|
-
if isinstance(
|
|
103
|
+
if isinstance(data_objective, (str, bytes, bytearray)):
|
|
93
104
|
# Soporte para bytes/bytearray convirtiendo el patrón si es necesario
|
|
94
105
|
pattern = self.regular_expression
|
|
95
|
-
if isinstance(
|
|
106
|
+
if isinstance(data_objective, (bytes, bytearray)) and isinstance(pattern, str):
|
|
96
107
|
pattern = pattern.encode()
|
|
97
108
|
|
|
98
|
-
if not re.fullmatch(pattern,
|
|
109
|
+
if not re.fullmatch(pattern, data_objective):
|
|
99
110
|
raise exceptions.RegularExpressionException(f"The value does not meet the required pattern: {self.regular_expression}")
|
|
111
|
+
|
|
112
|
+
return True
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
datavalue/__init__.py,sha256=QHthd6CQaDPqpvS3ay1r_Z7WvIleUXbTAottuML8nPA,66
|
|
2
|
+
datavalue/classes/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
3
|
+
datavalue/classes/primitive_data.py,sha256=qsKlds33RqR0bIGjy-5kgZdNBcrBMITbrvVx4HqeO-M,5281
|
|
4
|
+
datavalue/exceptions/__init__.py,sha256=T9X1N0kAv6RNTuTNQR7aTAxxvF25ihMsrtZGD-QZrBI,361
|
|
5
|
+
tests/test.py,sha256=8-AhuPJk0Yxt49MmbbdqGamhWM87T9mkbfmIU3BZZJk,1845
|
|
6
|
+
datavalue-0.1.4.dist-info/METADATA,sha256=85qTmyY5lcP96JpIi000IqYtvd-O23ZSTiL03SZymHc,1597
|
|
7
|
+
datavalue-0.1.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
8
|
+
datavalue-0.1.4.dist-info/top_level.txt,sha256=zlD2cuGB4gcH2hf8HIBij-0hqp_7e-c2e5nn6-A9j1Y,16
|
|
9
|
+
datavalue-0.1.4.dist-info/RECORD,,
|
tests/test.py
CHANGED
|
@@ -1,4 +1,62 @@
|
|
|
1
1
|
# Library import
|
|
2
|
-
import
|
|
2
|
+
from datavalue import PrimitiveData
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
# Phone number validation
|
|
5
|
+
print("="*10)
|
|
6
|
+
print("Validating phone number...")
|
|
7
|
+
phone_number = PrimitiveData(
|
|
8
|
+
data_type=str,
|
|
9
|
+
value="+34600111222",
|
|
10
|
+
minimum_length=7, # Minimum character length
|
|
11
|
+
maximum_length=15, # Maximum character length
|
|
12
|
+
minimum_size=None, # Not validate the minimum number
|
|
13
|
+
maximum_size=None, # Not validate the maximum number,
|
|
14
|
+
possible_values=None, # Not specify obligatory possible values
|
|
15
|
+
regular_expression=r"^\+[1-9]\d{6,14}$"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
print("Phone number validated sucessfully:", phone_number.value)
|
|
19
|
+
|
|
20
|
+
# Connection port validation
|
|
21
|
+
print("="*10)
|
|
22
|
+
print("Validating connection port...")
|
|
23
|
+
connection_port = PrimitiveData(
|
|
24
|
+
data_type=int,
|
|
25
|
+
value=45321,
|
|
26
|
+
minimum_length=1, # Maximum digits
|
|
27
|
+
maximum_length=5, # Minimum digits
|
|
28
|
+
minimum_size=1, # Minimum numerical value
|
|
29
|
+
maximum_size=65535, # Maximum numerical value
|
|
30
|
+
possible_values=None, # Possible options
|
|
31
|
+
regular_expression=None # Regular expression applied
|
|
32
|
+
)
|
|
33
|
+
print("Connection port validated:", connection_port.value)
|
|
34
|
+
|
|
35
|
+
# Transport protocol validation
|
|
36
|
+
print("="*10)
|
|
37
|
+
print("Validating transport protocol...")
|
|
38
|
+
transport_protocol = PrimitiveData(
|
|
39
|
+
data_type=str,
|
|
40
|
+
value="TCP",
|
|
41
|
+
maximum_length=None,
|
|
42
|
+
minimum_length=None,
|
|
43
|
+
minimum_size=None,
|
|
44
|
+
maximum_size=None,
|
|
45
|
+
possible_values=("TCP", "UDP"),
|
|
46
|
+
regular_expression=None
|
|
47
|
+
)
|
|
48
|
+
print("Transport protocol validated:", transport_protocol.value)
|
|
49
|
+
|
|
50
|
+
# Validating IPv4 address
|
|
51
|
+
print("="*10)
|
|
52
|
+
print("Validating IPv4 address...")
|
|
53
|
+
ip_address = PrimitiveData(
|
|
54
|
+
data_type=str,
|
|
55
|
+
value="192.168.0.1",
|
|
56
|
+
maximum_length=15,
|
|
57
|
+
minimum_length=7,
|
|
58
|
+
maximum_size=None, minimum_size=None,
|
|
59
|
+
possible_values=None,
|
|
60
|
+
regular_expression=r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
|
|
61
|
+
)
|
|
62
|
+
print("IPv4 address validated:", ip_address.value)
|
datavalue-0.1.3.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
datavalue/__init__.py,sha256=QHthd6CQaDPqpvS3ay1r_Z7WvIleUXbTAottuML8nPA,66
|
|
2
|
-
datavalue/classes/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
3
|
-
datavalue/classes/primitive_data.py,sha256=EuLPd53vAsGCiF0BgFeoZ_FBmzRmtMWf1Wmy2tbBENY,4845
|
|
4
|
-
datavalue/exceptions/__init__.py,sha256=T9X1N0kAv6RNTuTNQR7aTAxxvF25ihMsrtZGD-QZrBI,361
|
|
5
|
-
tests/test.py,sha256=lmbOvi7J2G-wWTV45F5adAmRhiht0djYIrkOyRiYjv4,70
|
|
6
|
-
datavalue-0.1.3.dist-info/METADATA,sha256=VxIFAvmTGytx1Hi5jPiD8pYXwOX1skF9CAueOjOzMK8,1597
|
|
7
|
-
datavalue-0.1.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
8
|
-
datavalue-0.1.3.dist-info/top_level.txt,sha256=zlD2cuGB4gcH2hf8HIBij-0hqp_7e-c2e5nn6-A9j1Y,16
|
|
9
|
-
datavalue-0.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|