summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-06-22 08:44:46 +0200
committerFlorian Bruhin <me@the-compiler.org>2012-06-22 08:44:46 +0200
commit567572e3afa1df22d1cceaf37a93a9b2f4d5fb58 (patch)
tree00e0cf207062aad2f675757d7842ed8717d7677b
parentffa2274c375801c8df2ac4bee84a1f154bff0ad2 (diff)
downloadxdd2esi-567572e3afa1df22d1cceaf37a93a9b2f4d5fb58.tar.gz
xdd2esi-567572e3afa1df22d1cceaf37a93a9b2f4d5fb58.zip
Make _set_string_length() in xddlib a function, not a method
-rw-r--r--xddlib.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/xddlib.py b/xddlib.py
index 5d18d3b..6bb7e37 100644
--- a/xddlib.py
+++ b/xddlib.py
@@ -118,18 +118,6 @@ class XDDFile:
_setattributes(subobject, child)
self.objlist.append(canobject)
- def _set_string_length(self, obj):
- """ Sets the correct string length in a datatype """
- if obj.datatype.type_ == 'string':
- basesize = 8
- elif obj.datatype.type_ == 'unicode':
- basesize = 16
- default = obj.default
- length = len(default) + 1
- 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)
@@ -205,9 +193,9 @@ class XDDFile:
py_datatype = self._get_py_datatype(obj)
obj.datatype = py_datatype
special_handlers = {
- 'string': self._set_string_length,
+ 'string': _set_string_length,
'octet': self._set_octet_length,
- 'unicode': self._set_string_length,
+ 'unicode': _set_string_length,
}
try:
handler = special_handlers[py_datatype.type_]
@@ -344,4 +332,14 @@ def _getchildren(xmlobject):
children.append(childattr)
return children
-
+def _set_string_length(obj):
+ """ Sets the correct string length in a datatype """
+ if obj.datatype.type_ == 'string':
+ basesize = 8
+ elif obj.datatype.type_ == 'unicode':
+ basesize = 16
+ default = obj.default
+ length = len(default) + 1
+ size = basesize * length
+ obj.datatype.length = length
+ obj.datatype.size = size