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): def __getitem__(self, item):
return self.value[item] return self.value[item]
def __iter__(self):
return iter(self.value)
def encode(self, taglist): def encode(self, taglist):
if _debug: _SequenceOf._debug("(%r)encode %r", self.__class__.__name__, taglist) if _debug: _SequenceOf._debug("(%r)encode %r", self.__class__.__name__, taglist)
for value in self.value: for value in self.value:
@ -595,6 +598,9 @@ def ArrayOf(klass):
del self.value[item] del self.value[item]
self.value[0] -= 1 self.value[0] -= 1
def __iter__(self):
return iter(self.value[1:])
def index(self, value): def index(self, value):
# only search through values # only search through values
for i in range(1, self.value[0] + 1): 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 # build a property dictionary by going through the class and all its parents
_properties = {} _properties = {}
for c in cls.__mro__: for c in cls.__mro__:
if _debug: register_object_type._debug(" - c: %r", c)
for prop in getattr(c, 'properties', []): for prop in getattr(c, 'properties', []):
if prop.identifier not in _properties: if prop.identifier not in _properties:
_properties[prop.identifier] = prop _properties[prop.identifier] = prop
@ -209,6 +210,13 @@ class Property(Logging):
)) ))
# if it's atomic, make sure it's valid # 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): elif issubclass(self.datatype, Atomic):
if _debug: Property._debug(" - property is atomic, checking value") if _debug: Property._debug(" - property is atomic, checking value")
if not self.datatype.is_valid(value): if not self.datatype.is_valid(value):

View File

@ -449,6 +449,8 @@ class Atomic(object):
_app_tag = None _app_tag = None
def __cmp__(self, other): def __cmp__(self, other):
# sys.stderr.write("__cmp__ %r %r\n" % (self, other))
# hoop jump it # hoop jump it
if not isinstance(other, self.__class__): if not isinstance(other, self.__class__):
other = self.__class__(other) other = self.__class__(other)
@ -461,6 +463,26 @@ class Atomic(object):
else: else:
return 0 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 @classmethod
def coerce(cls, arg): def coerce(cls, arg):
"""Given an arg, return the appropriate value given the class.""" """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") raise RuntimeError("vendorIdentifier required to auto-register the LocalDeviceObject class")
register_object_type(self.__class__, vendor_id=kwargs['vendorIdentifier']) register_object_type(self.__class__, vendor_id=kwargs['vendorIdentifier'])
# check for local time # check for properties this class implements
if 'localDate' in kwargs: if 'localDate' in kwargs:
raise RuntimeError("localDate is provided by LocalDeviceObject and cannot be overridden") raise RuntimeError("localDate is provided by LocalDeviceObject and cannot be overridden")
if 'localTime' in kwargs: if 'localTime' in kwargs:

View File

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

View File

@ -406,6 +406,9 @@ def SequenceOf(klass):
def __getitem__(self, item): def __getitem__(self, item):
return self.value[item] return self.value[item]
def __iter__(self):
return iter(self.value)
def encode(self, taglist): def encode(self, taglist):
if _debug: _SequenceOf._debug("(%r)encode %r", self.__class__.__name__, taglist) if _debug: _SequenceOf._debug("(%r)encode %r", self.__class__.__name__, taglist)
for value in self.value: for value in self.value:
@ -593,6 +596,9 @@ def ArrayOf(klass):
del self.value[item] del self.value[item]
self.value[0] -= 1 self.value[0] -= 1
def __iter__(self):
return iter(self.value[1:])
def index(self, value): def index(self, value):
# only search through values # only search through values
for i in range(1, self.value[0] + 1): 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 # build a property dictionary by going through the class and all its parents
_properties = {} _properties = {}
for c in cls.__mro__: for c in cls.__mro__:
if _debug: register_object_type._debug(" - c: %r", c)
for prop in getattr(c, 'properties', []): for prop in getattr(c, 'properties', []):
if prop.identifier not in _properties: if prop.identifier not in _properties:
_properties[prop.identifier] = prop _properties[prop.identifier] = prop
@ -210,6 +211,13 @@ class Property:
)) ))
# if it's atomic, make sure it's valid # 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): elif issubclass(self.datatype, Atomic):
if _debug: Property._debug(" - property is atomic, checking value") if _debug: Property._debug(" - property is atomic, checking value")
if not self.datatype.is_valid(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") raise RuntimeError("vendorIdentifier required to auto-register the LocalDeviceObject class")
register_object_type(self.__class__, vendor_id=kwargs['vendorIdentifier']) register_object_type(self.__class__, vendor_id=kwargs['vendorIdentifier'])
# check for local time # check for properties this class implements
if 'localDate' in kwargs: if 'localDate' in kwargs:
raise RuntimeError("localDate is provided by LocalDeviceObject and cannot be overridden") raise RuntimeError("localDate is provided by LocalDeviceObject and cannot be overridden")
if 'localTime' in kwargs: if 'localTime' in kwargs: