summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-06-22 08:52:56 +0200
committerFlorian Bruhin <me@the-compiler.org>2012-06-22 08:52:56 +0200
commiteac86d09fca10d08ac6c25c0e864a9602b9449a2 (patch)
treefa6c5bd2b9501e146bfa2e3db5f17ab31f5e6c3f
parenta507a05eeabf9e6375cf8716cdb6220aa4cb8911 (diff)
downloadxdd2esi-eac86d09fca10d08ac6c25c0e864a9602b9449a2.tar.gz
xdd2esi-eac86d09fca10d08ac6c25c0e864a9602b9449a2.zip
Make _convert_cast_*() in xddlib a function, not a method
-rw-r--r--xddlib.py57
1 files changed, 27 insertions, 30 deletions
diff --git a/xddlib.py b/xddlib.py
index 740e23d..94bc432 100644
--- a/xddlib.py
+++ b/xddlib.py
@@ -146,14 +146,14 @@ class XDDFile:
value = getattr(obj, label)
unit = self._convert_cast_get_unit(obj, units[label], value)
convfuncs = {
- 'truefalse': self._convert_cast_truefalse,
- 'boolean': self._convert_cast_hexint,
- 'integer': self._convert_cast_int,
- 'float': self._convert_cast_hexint,
- 'hexint': self._convert_cast_hexint,
- 'string': self._convert_cast_nop,
- 'octet': self._convert_cast_nop,
- 'unicode': self._convert_cast_nop,
+ 'truefalse': _convert_cast_truefalse,
+ 'boolean': _convert_cast_hexint,
+ 'integer': _convert_cast_int,
+ 'float': _convert_cast_hexint,
+ 'hexint': _convert_cast_hexint,
+ 'string': _convert_cast_nop,
+ 'octet': _convert_cast_nop,
+ 'unicode': _convert_cast_nop,
}
convfunc = convfuncs.get(unit)
try:
@@ -184,27 +184,6 @@ class XDDFile:
newunit = unit
return newunit
- def _convert_cast_truefalse(self, value):
- """ Converts to a python boolean """
- conv = { 'true': True, 'false': False }
- newvalue = conv[value]
- return newvalue
-
- def _convert_cast_int(self, value):
- """ Converts to an integer """
- newvalue = int(value, 10)
- return newvalue
-
- def _convert_cast_hexint(self, value):
- """ Converts from a hexadecimal integer-string to an integer """
- newvalue = int(value, 16)
- return newvalue
-
- def _convert_cast_nop(self, value):
- """ Doesn't convert anything """
- return value
-
-
def _is_reserved(objdict):
""" Returns true if an object is reserved """
match = re.match('^reserved[0-9a-fA_F]*$', objdict['name'])
@@ -344,4 +323,22 @@ def _convert_datatypes(obj):
else:
handler(obj)
-
+def _convert_cast_truefalse(value):
+ """ Converts to a python boolean """
+ conv = { 'true': True, 'false': False }
+ newvalue = conv[value]
+ return newvalue
+
+def _convert_cast_int(value):
+ """ Converts to an integer """
+ newvalue = int(value, 10)
+ return newvalue
+
+def _convert_cast_hexint(value):
+ """ Converts from a hexadecimal integer-string to an integer """
+ newvalue = int(value, 16)
+ return newvalue
+
+def _convert_cast_nop(value):
+ """ Doesn't convert anything """
+ return value