check virtual lengths, fix imports

This commit is contained in:
protolambda 2019-06-18 02:04:10 +02:00
parent 4c2adcc5e6
commit 73ba419d64
1 changed files with 5 additions and 2 deletions

View File

@ -268,7 +268,7 @@ class Elements(ParamsBase, metaclass=ElementsType):
@classmethod
def value_check(cls, value):
return all(isinstance(v, cls.elem_type) for v in value)
return all(isinstance(v, cls.elem_type) for v in value) and len(value) <= cls.length
@classmethod
def extract_args(cls, *args):
@ -316,6 +316,7 @@ class Vector(Elements):
@classmethod
def value_check(cls, value):
# check length limit strictly
return len(value) == cls.length and super().value_check(value)
@classmethod
@ -350,7 +351,8 @@ class BytesLike(Elements, metaclass=BytesType):
@classmethod
def value_check(cls, value):
return isinstance(value, bytes)
# check type and virtual length limit
return isinstance(value, bytes) and len(value) <= cls.length
def __str__(self):
cls = self.__class__
@ -376,6 +378,7 @@ class BytesN(BytesLike):
@classmethod
def value_check(cls, value):
# check length limit strictly
return len(value) == cls.length and super().value_check(value)
@classmethod