version as of 2025-01-09 from ultrasound PC

This commit is contained in:
Ultrasound PC
2025-01-09 09:59:33 +01:00
parent efca358c72
commit a1fa9f1cbb
12 changed files with 757 additions and 306 deletions

View File

@@ -760,7 +760,7 @@ class ArrayOf(DataType):
def __call__(self, value):
"""validate an external representation to an internal one"""
if isinstance(value, (tuple, list)):
try:
# check number of elements
if self.minlen is not None and len(value) < self.minlen:
raise BadValueError(
@@ -768,11 +768,12 @@ class ArrayOf(DataType):
self.minlen)
if self.maxlen is not None and len(value) > self.maxlen:
raise BadValueError(
'Array too big, holds at most %d elements!' % self.minlen)
# apply subtype valiation to all elements and return as list
'Array too big, holds at most %d elements!' % self.maxlen)
# apply subtype valdiation to all elements and return as list
return tuple(self.members(elem) for elem in value)
raise BadValueError(
'Can not convert %s to ArrayOf DataType!' % repr(value))
except TypeError:
raise BadValueError('%s can not be converted to ArrayOf DataType!'
% type(value).__name__) from None
def export_value(self, value):
"""returns a python object fit for serialisation"""
@@ -842,6 +843,7 @@ class TupleOf(DataType):
return tuple(sub(elem)
for sub, elem in zip(self.members, value))
except Exception as exc:
print(value)
raise BadValueError('Can not validate:', str(exc)) from None
def export_value(self, value):