1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-10-27 00:57:47 +08:00

bring in code from older branch #96

This commit is contained in:
Joel Bender
2017-12-06 22:49:46 -05:00
parent ba086d292d
commit de1d895c87
5 changed files with 977 additions and 9 deletions

View File

@@ -406,6 +406,9 @@ def SequenceOf(klass):
def __getitem__(self, item):
return self.value[item]
def __iter__(self):
return iter(self.value)
def encode(self, taglist):
if _debug: _SequenceOf._debug("(%r)encode %r", self.__class__.__name__, taglist)
for value in self.value:
@@ -593,6 +596,9 @@ def ArrayOf(klass):
del self.value[item]
self.value[0] -= 1
def __iter__(self):
return iter(self.value[1:])
def index(self, value):
# only search through values
for i in range(1, self.value[0] + 1):
@@ -1153,7 +1159,7 @@ class Any:
#
@bacpypes_debugging
class AnyAtomic:
class AnyAtomic(Atomic):
def __init__(self, arg=None):
if _debug: AnyAtomic._debug("__init__ %r", arg)
@@ -1184,8 +1190,13 @@ class AnyAtomic:
# get the data
self.value = tag.app_to_object()
@classmethod
def is_valid(cls, arg):
"""Return True if arg is valid value for the class."""
return isinstance(arg, Atomic) and not isinstance(arg, AnyAtomic)
def __str__(self):
return "AnyAtomic(%s)" % (str(self.value), )
return "%s(%s)" % (self.__class__.__name__, str(self.value))
def __repr__(self):
desc = self.__module__ + '.' + self.__class__.__name__

View File

@@ -211,6 +211,13 @@ class Property:
))
# if it's atomic, make sure it's valid
if issubclass(self.datatype, AnyAtomic):
if _debug: Property._debug(" - property is any atomic, checking value")
if not isinstance(value, Atomic):
raise InvalidParameterDatatype("%s must be an atomic instance" % (
self.identifier,
))
elif issubclass(self.datatype, Atomic):
if _debug: Property._debug(" - property is atomic, checking value")
if not self.datatype.is_valid(value):