summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-06-22 08:56:04 +0200
committerFlorian Bruhin <me@the-compiler.org>2012-06-22 08:56:04 +0200
commit42024b77b06007709a44995820b0342aa1b7ef62 (patch)
tree91e4d8ec7aff03ae1565e0fb28c23b1bc6ae0a9f
parent2feedcab104a757b5f1185cd2a2db8d3406e8cd7 (diff)
downloadxdd2esi-42024b77b06007709a44995820b0342aa1b7ef62.tar.gz
xdd2esi-42024b77b06007709a44995820b0342aa1b7ef62.zip
Make _convert_cast in xddlib a function, not a method
-rw-r--r--xddlib.py48
1 files changed, 24 insertions, 24 deletions
diff --git a/xddlib.py b/xddlib.py
index 58d52a4..dcc2220 100644
--- a/xddlib.py
+++ b/xddlib.py
@@ -70,7 +70,7 @@ class XDDFile:
# Convert numeric object types to datatype objects
_convert_objecttypes(obj)
# Cast strings to ints/...
- self._convert_cast(obj)
+ _convert_cast(obj)
def shift(self, rangestart, rangeend, offset):
""" Shifts a certain range of objects """
@@ -118,29 +118,6 @@ class XDDFile:
_setattributes(subobject, child)
self.objlist.append(canobject)
- def _convert_cast(self, obj):
- """ Converts XML-strings to the right types """
- # Available types:
- #
- # 'truefalse': Convert to a Python boolean
- # 'true' - True / 'false' - False
- # 'integer': Convert to an Integer
- # int('1')
- # 'hexint': Convert to an Integer, original value hex
- # int('1', 16)
- # 'dt': Type depends on the datatype
- units = {
- 'pdomapping': 'truefalse',
- 'index': 'hexint',
- 'subindex': 'hexint',
- 'default': 'dt',
- 'maximum': 'dt',
- 'minimum': 'dt',
- }
- 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
- _convert_cast_attribute(obj, label, units)
-
def _is_reserved(objdict):
""" Returns true if an object is reserved """
match = re.match('^reserved[0-9a-fA_F]*$', objdict['name'])
@@ -280,6 +257,29 @@ def _convert_datatypes(obj):
else:
handler(obj)
+def _convert_cast(obj):
+ """ Converts XML-strings to the right types """
+ # Available types:
+ #
+ # 'truefalse': Convert to a Python boolean
+ # 'true' - True / 'false' - False
+ # 'integer': Convert to an Integer
+ # int('1')
+ # 'hexint': Convert to an Integer, original value hex
+ # int('1', 16)
+ # 'dt': Type depends on the datatype
+ units = {
+ 'pdomapping': 'truefalse',
+ 'index': 'hexint',
+ 'subindex': 'hexint',
+ 'default': 'dt',
+ 'maximum': 'dt',
+ 'minimum': 'dt',
+ }
+ 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
+ _convert_cast_attribute(obj, label, units)
+
def _convert_cast_attribute(obj, label, units):
""" Converts an attribute of an object to the right type """
value = getattr(obj, label)