summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-06-22 08:55:05 +0200
committerFlorian Bruhin <me@the-compiler.org>2012-06-22 08:55:05 +0200
commit2feedcab104a757b5f1185cd2a2db8d3406e8cd7 (patch)
treee949f5495aee76f9ec0be40631cdca87b61f0146
parentfb33ac4ba6df519b23a490e92c6f0586669f54c9 (diff)
downloadxdd2esi-2feedcab104a757b5f1185cd2a2db8d3406e8cd7.tar.gz
xdd2esi-2feedcab104a757b5f1185cd2a2db8d3406e8cd7.zip
Make _convert_cast_attribute in xddlib a function, not a method
-rw-r--r--xddlib.py58
1 files changed, 29 insertions, 29 deletions
diff --git a/xddlib.py b/xddlib.py
index 3c886e9..58d52a4 100644
--- a/xddlib.py
+++ b/xddlib.py
@@ -139,35 +139,7 @@ class XDDFile:
}
for label in units: # Get all the unit definitions and see if the key
if getattr(obj, label) is not None: # is in the active object
- self._convert_cast_attribute(obj, label, units)
-
- def _convert_cast_attribute(self, obj, label, units):
- """ Converts an attribute of an object to the right type """
- value = getattr(obj, label)
- unit = _convert_cast_get_unit(obj, units[label], value)
- convfuncs = {
- '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:
- newvalue = convfunc(value)
- except (ValueError, KeyError):
- warnings.warn("{}={} in {} is not a valid {}!".format(label,
- value, obj, unit), CastConvertWarning)
- except TypeError: # None
- #warnings.warn("Can't convert {}={} in {} to {}!".format(label,
- # value, obj, unit), NoCastConvertFunctionWarning)
- warnings.warn("Can't convert {}={} to {}!".format(label, value,
- unit), NoCastConvertFunctionWarning)
- newvalue = value
- setattr(obj, label, newvalue)
+ _convert_cast_attribute(obj, label, units)
def _is_reserved(objdict):
""" Returns true if an object is reserved """
@@ -308,6 +280,34 @@ def _convert_datatypes(obj):
else:
handler(obj)
+def _convert_cast_attribute(obj, label, units):
+ """ Converts an attribute of an object to the right type """
+ value = getattr(obj, label)
+ unit = _convert_cast_get_unit(obj, units[label], value)
+ convfuncs = {
+ '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:
+ newvalue = convfunc(value)
+ except (ValueError, KeyError):
+ warnings.warn("{}={} in {} is not a valid {}!".format(label,
+ value, obj, unit), CastConvertWarning)
+ except TypeError: # None
+ #warnings.warn("Can't convert {}={} in {} to {}!".format(label,
+ # value, obj, unit), NoCastConvertFunctionWarning)
+ warnings.warn("Can't convert {}={} to {}!".format(label, value,
+ unit), NoCastConvertFunctionWarning)
+ newvalue = value
+ setattr(obj, label, newvalue)
+
def _convert_cast_get_unit(obj, unit, value):
"""
Gets the unit of an object attribute (from the datatype if needed)