1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

sync up the different python versions

This commit is contained in:
Joel Bender 2017-12-06 23:10:57 -05:00
parent de1d895c87
commit 5e19456e23
8 changed files with 74 additions and 2 deletions

View File

@ -405,6 +405,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:
@ -595,6 +598,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):

View File

@ -81,6 +81,7 @@ def register_object_type(cls=None, vendor_id=0):
# build a property dictionary by going through the class and all its parents
_properties = {}
for c in cls.__mro__:
if _debug: register_object_type._debug(" - c: %r", c)
for prop in getattr(c, 'properties', []):
if prop.identifier not in _properties:
_properties[prop.identifier] = prop
@ -209,6 +210,13 @@ class Property(Logging):
))
# 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):

View File

@ -449,6 +449,8 @@ class Atomic(object):
_app_tag = None
def __cmp__(self, other):
# sys.stderr.write("__cmp__ %r %r\n" % (self, other))
# hoop jump it
if not isinstance(other, self.__class__):
other = self.__class__(other)
@ -461,6 +463,26 @@ class Atomic(object):
else:
return 0
def __lt__(self, other):
# sys.stderr.write("__lt__ %r %r\n" % (self, other))
# hoop jump it
if not isinstance(other, self.__class__):
other = self.__class__(other)
# now compare the values
return (self.value < other.value)
def __eq__(self, other):
# sys.stderr.write("__eq__ %r %r\n" % (self, other))
# hoop jump it
if not isinstance(other, self.__class__):
other = self.__class__(other)
# now compare the values
return self.value == other.value
@classmethod
def coerce(cls, arg):
"""Given an arg, return the appropriate value given the class."""

View File

@ -103,7 +103,7 @@ class LocalDeviceObject(CurrentPropertyListMixIn, DeviceObject):
raise RuntimeError("vendorIdentifier required to auto-register the LocalDeviceObject class")
register_object_type(self.__class__, vendor_id=kwargs['vendorIdentifier'])
# check for local time
# check for properties this class implements
if 'localDate' in kwargs:
raise RuntimeError("localDate is provided by LocalDeviceObject and cannot be overridden")
if 'localTime' in kwargs:

View File

@ -453,6 +453,8 @@ class Atomic(object):
_app_tag = None
def __cmp__(self, other):
# sys.stderr.write("__cmp__ %r %r\n" % (self, other))
# hoop jump it
if not isinstance(other, self.__class__):
other = self.__class__(other)
@ -465,6 +467,26 @@ class Atomic(object):
else:
return 0
def __lt__(self, other):
# sys.stderr.write("__lt__ %r %r\n" % (self, other))
# hoop jump it
if not isinstance(other, self.__class__):
other = self.__class__(other)
# now compare the values
return (self.value < other.value)
def __eq__(self, other):
# sys.stderr.write("__eq__ %r %r\n" % (self, other))
# hoop jump it
if not isinstance(other, self.__class__):
other = self.__class__(other)
# now compare the values
return self.value == other.value
@classmethod
def coerce(cls, arg):
"""Given an arg, return the appropriate value given the class."""

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):

View File

@ -81,6 +81,7 @@ def register_object_type(cls=None, vendor_id=0):
# build a property dictionary by going through the class and all its parents
_properties = {}
for c in cls.__mro__:
if _debug: register_object_type._debug(" - c: %r", c)
for prop in getattr(c, 'properties', []):
if prop.identifier not in _properties:
_properties[prop.identifier] = prop
@ -210,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):

View File

@ -104,7 +104,7 @@ class LocalDeviceObject(CurrentPropertyListMixIn, DeviceObject):
raise RuntimeError("vendorIdentifier required to auto-register the LocalDeviceObject class")
register_object_type(self.__class__, vendor_id=kwargs['vendorIdentifier'])
# check for local time
# check for properties this class implements
if 'localDate' in kwargs:
raise RuntimeError("localDate is provided by LocalDeviceObject and cannot be overridden")
if 'localTime' in kwargs: