From 5e19456e23727a049ad16efdd9c50cf6f5c3721d Mon Sep 17 00:00:00 2001 From: Joel Bender Date: Wed, 6 Dec 2017 23:10:57 -0500 Subject: [PATCH] sync up the different python versions --- py25/bacpypes/constructeddata.py | 6 ++++++ py25/bacpypes/object.py | 8 ++++++++ py25/bacpypes/primitivedata.py | 22 ++++++++++++++++++++++ py25/bacpypes/service/device.py | 2 +- py27/bacpypes/primitivedata.py | 22 ++++++++++++++++++++++ py34/bacpypes/constructeddata.py | 6 ++++++ py34/bacpypes/object.py | 8 ++++++++ py34/bacpypes/service/device.py | 2 +- 8 files changed, 74 insertions(+), 2 deletions(-) diff --git a/py25/bacpypes/constructeddata.py b/py25/bacpypes/constructeddata.py index f06d2ee..5a30553 100755 --- a/py25/bacpypes/constructeddata.py +++ b/py25/bacpypes/constructeddata.py @@ -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): diff --git a/py25/bacpypes/object.py b/py25/bacpypes/object.py index 3bbac83..ed66fdc 100755 --- a/py25/bacpypes/object.py +++ b/py25/bacpypes/object.py @@ -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): diff --git a/py25/bacpypes/primitivedata.py b/py25/bacpypes/primitivedata.py index 64070aa..840a7b6 100755 --- a/py25/bacpypes/primitivedata.py +++ b/py25/bacpypes/primitivedata.py @@ -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.""" diff --git a/py25/bacpypes/service/device.py b/py25/bacpypes/service/device.py index 87e618f..94958bf 100644 --- a/py25/bacpypes/service/device.py +++ b/py25/bacpypes/service/device.py @@ -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: diff --git a/py27/bacpypes/primitivedata.py b/py27/bacpypes/primitivedata.py index 91c10d7..1bdb8f1 100755 --- a/py27/bacpypes/primitivedata.py +++ b/py27/bacpypes/primitivedata.py @@ -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.""" diff --git a/py34/bacpypes/constructeddata.py b/py34/bacpypes/constructeddata.py index 88fe28d..56b6636 100755 --- a/py34/bacpypes/constructeddata.py +++ b/py34/bacpypes/constructeddata.py @@ -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): diff --git a/py34/bacpypes/object.py b/py34/bacpypes/object.py index 9f31dd9..8738118 100755 --- a/py34/bacpypes/object.py +++ b/py34/bacpypes/object.py @@ -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): diff --git a/py34/bacpypes/service/device.py b/py34/bacpypes/service/device.py index f8871c7..647714b 100644 --- a/py34/bacpypes/service/device.py +++ b/py34/bacpypes/service/device.py @@ -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: