summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-06-22 08:46:29 +0200
committerFlorian Bruhin <me@the-compiler.org>2012-06-22 08:46:29 +0200
commit74fb85da1f1bf0489ddb453827ab63b8e085706f (patch)
tree7ff53458dbe7a238b9f8b0e83299f1454629bf97
parent567572e3afa1df22d1cceaf37a93a9b2f4d5fb58 (diff)
downloadxdd2esi-74fb85da1f1bf0489ddb453827ab63b8e085706f.tar.gz
xdd2esi-74fb85da1f1bf0489ddb453827ab63b8e085706f.zip
Make _set_octet_length() in xddlib a function, not a method
-rw-r--r--xddlib.py40
1 files changed, 20 insertions, 20 deletions
diff --git a/xddlib.py b/xddlib.py
index 6bb7e37..4b3d379 100644
--- a/xddlib.py
+++ b/xddlib.py
@@ -118,25 +118,6 @@ class XDDFile:
_setattributes(subobject, child)
self.objlist.append(canobject)
- def _set_octet_length(self, obj):
- """ Sets the correct octet string length """
- # This converts a string like 0x0000 to it's size in bytes. (here: 2)
- # First we remove 2 from the length (the "0x")
- # Then we add 1 again to round up, then we integer-divide
- # (which rounds down).This way, if the length is dividable by 2,
- # adding 1 won't hurt. If it isn't, we will round up.
- #
- # Examples:
- # 0x000000 -> (8 - 2 + 1) // 2 == 3
- # 0x000 -> 2
- # 0x00 -> 1
- # 0x0 -> 1
- default = obj.default
- length = (len(default) - 2 + 1) // 2
- size = 8 * length
- obj.datatype.length = length
- obj.datatype.size = size
-
def _get_py_datatype(self, obj):
""" Returns the Datatype of a CAN datatype """
# signed: If the type is signed (True) or unsigned
@@ -194,7 +175,7 @@ class XDDFile:
obj.datatype = py_datatype
special_handlers = {
'string': _set_string_length,
- 'octet': self._set_octet_length,
+ 'octet': _set_octet_length,
'unicode': _set_string_length,
}
try:
@@ -343,3 +324,22 @@ def _set_string_length(obj):
size = basesize * length
obj.datatype.length = length
obj.datatype.size = size
+
+def _set_octet_length(self, obj):
+ """ Sets the correct octet string length """
+ # This converts a string like 0x0000 to it's size in bytes. (here: 2).
+ # First we remove 2 from the length (the "0x").
+ # Then we add 1 again to round up, then we integer-divide (which rounds
+ # down). This way, if the length is dividable by 2, adding 1 won't hurt.
+ # If it isn't, we will round up.
+ #
+ # Examples:
+ # 0x000000 -> (8 - 2 + 1) // 2 == 3
+ # 0x000 -> 2
+ # 0x00 -> 1
+ # 0x0 -> 1
+ default = obj.default
+ length = (len(default) - 2 + 1) // 2
+ size = 8 * length
+ obj.datatype.length = length
+ obj.datatype.size = size