mirror of
https://github.com/JoelBender/bacpypes
synced 2025-09-28 22:15:23 +08:00
a little too aggressive copy/paste (#258)
This commit is contained in:
parent
8b1ae6617d
commit
7bd978ffaa
|
@ -598,13 +598,17 @@ class Unsigned(Atomic):
|
|||
_high_limit = None
|
||||
|
||||
def __init__(self, arg=None):
|
||||
self.value = 0
|
||||
self.value = 0L
|
||||
|
||||
if arg is None:
|
||||
pass
|
||||
elif isinstance(arg, Tag):
|
||||
self.decode(arg)
|
||||
elif isinstance(arg, int):
|
||||
if not self.is_valid(arg):
|
||||
raise ValueError("value out of range")
|
||||
self.value = long(arg)
|
||||
elif isinstance(arg, long):
|
||||
if not self.is_valid(arg):
|
||||
raise ValueError("value out of range")
|
||||
self.value = arg
|
||||
|
@ -617,10 +621,10 @@ class Unsigned(Atomic):
|
|||
|
||||
def encode(self, tag):
|
||||
# rip apart the number
|
||||
data = bytearray(struct.pack('>L', self.value))
|
||||
data = struct.pack('>L', self.value)
|
||||
|
||||
# reduce the value to the smallest number of octets
|
||||
while (len(data) > 1) and (data[0] == 0):
|
||||
while (len(data) > 1) and (data[0] == '\x00'):
|
||||
del data[0]
|
||||
|
||||
# encode the tag
|
||||
|
@ -633,9 +637,9 @@ class Unsigned(Atomic):
|
|||
raise InvalidTag("invalid tag length")
|
||||
|
||||
# get the data
|
||||
rslt = 0
|
||||
rslt = 0L
|
||||
for c in tag.tagData:
|
||||
rslt = (rslt << 8) + c
|
||||
rslt = (rslt << 8) + ord(c)
|
||||
|
||||
# save the result
|
||||
self.value = rslt
|
||||
|
@ -643,7 +647,7 @@ class Unsigned(Atomic):
|
|||
@classmethod
|
||||
def is_valid(cls, arg):
|
||||
"""Return True if arg is valid value for the class."""
|
||||
if not isinstance(arg, int) or isinstance(arg, bool):
|
||||
if not isinstance(arg, (int, long)) or isinstance(arg, bool):
|
||||
return False
|
||||
if (arg < cls._low_limit):
|
||||
return False
|
||||
|
|
|
@ -602,13 +602,17 @@ class Unsigned(Atomic):
|
|||
_high_limit = None
|
||||
|
||||
def __init__(self, arg=None):
|
||||
self.value = 0
|
||||
self.value = 0L
|
||||
|
||||
if arg is None:
|
||||
pass
|
||||
elif isinstance(arg, Tag):
|
||||
self.decode(arg)
|
||||
elif isinstance(arg, int):
|
||||
if not self.is_valid(arg):
|
||||
raise ValueError("value out of range")
|
||||
self.value = long(arg)
|
||||
elif isinstance(arg, long):
|
||||
if not self.is_valid(arg):
|
||||
raise ValueError("value out of range")
|
||||
self.value = arg
|
||||
|
@ -637,9 +641,9 @@ class Unsigned(Atomic):
|
|||
raise InvalidTag("invalid tag length")
|
||||
|
||||
# get the data
|
||||
rslt = 0
|
||||
rslt = 0L
|
||||
for c in tag.tagData:
|
||||
rslt = (rslt << 8) + c
|
||||
rslt = (rslt << 8) + ord(c)
|
||||
|
||||
# save the result
|
||||
self.value = rslt
|
||||
|
@ -647,7 +651,7 @@ class Unsigned(Atomic):
|
|||
@classmethod
|
||||
def is_valid(cls, arg):
|
||||
"""Return True if arg is valid value for the class."""
|
||||
if not isinstance(arg, int) or isinstance(arg, bool):
|
||||
if not isinstance(arg, (int, long)) or isinstance(arg, bool):
|
||||
return False
|
||||
if (arg < cls._low_limit):
|
||||
return False
|
||||
|
|
Loading…
Reference in New Issue
Block a user