summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-06-22 08:41:11 +0200
committerFlorian Bruhin <me@the-compiler.org>2012-06-22 08:41:55 +0200
commit572b9287bbfce61bde41b22d88fe281bccac2d58 (patch)
treeefe37ebe5f422b28885cae2a32e2e9cc3dcaf528
parent2a609152115bb183421db045ef0e8d7bb36e1836 (diff)
downloadxdd2esi-572b9287bbfce61bde41b22d88fe281bccac2d58.tar.gz
xdd2esi-572b9287bbfce61bde41b22d88fe281bccac2d58.zip
Make _setattributes in xddlib a function, not a method
-rw-r--r--xddlib.py60
1 files changed, 31 insertions, 29 deletions
diff --git a/xddlib.py b/xddlib.py
index 8a3d7cc..9648bb0 100644
--- a/xddlib.py
+++ b/xddlib.py
@@ -120,40 +120,13 @@ class XDDFile:
for xmlobject in xmlobjects:
canobject = canlib.CanObject()
attributes = dict(xmlobject.attrib)
- self._setattributes(canobject, attributes)
+ _setattributes(canobject, attributes)
if len(xmlobject) > 0: # check if the object has subobjects
for child in self._getchildren(xmlobject):
subobject = canobject.newchild()
- self._setattributes(subobject, child)
+ _setattributes(subobject, child)
self.objlist.append(canobject)
- def _setattributes(self, canobj, attributes):
- """ Sets object attributes """
- xddmapping = {
- # XDD: CanObject
- 'index': 'index',
- 'subIndex': 'subindex',
- 'name': 'name',
- 'dataType': 'datatype',
- 'accessType': 'accesstype',
- 'objectType': 'objecttype',
- 'PDOmapping': 'pdomapping',
- 'defaultValue': 'default',
- 'lowLimit': 'minimum',
- 'highLimit': 'maximum',
- 'objFlags': 'objflags',
- }
- for label in attributes:
- try:
- canobjectlabel = xddmapping[label]
- except KeyError:
- warnings.warn("The attribute {} is unknown and will be "
- "ignored!".format(label), UnknownAttributeWarning)
- else:
- value = attributes[label]
- setattr(canobj, canobjectlabel, value)
- canobj.convertstate = 'xdd'
-
def _set_string_length(self, obj):
""" Sets the correct string length in a datatype """
if obj.datatype.type_ == 'string':
@@ -343,3 +316,32 @@ def _is_reserved(objdict):
""" Returns true if an object is reserved """
match = re.match('^reserved[0-9a-fA_F]*$', objdict['name'])
return bool(match)
+
+def _setattributes(canobj, attributes):
+ """ Sets object attributes """
+ xddmapping = {
+ # XDD: CanObject
+ 'index': 'index',
+ 'subIndex': 'subindex',
+ 'name': 'name',
+ 'dataType': 'datatype',
+ 'accessType': 'accesstype',
+ 'objectType': 'objecttype',
+ 'PDOmapping': 'pdomapping',
+ 'defaultValue': 'default',
+ 'lowLimit': 'minimum',
+ 'highLimit': 'maximum',
+ 'objFlags': 'objflags',
+ }
+ for label in attributes:
+ try:
+ canobjectlabel = xddmapping[label]
+ except KeyError:
+ warnings.warn("The attribute {} is unknown and will be ignored!".
+ format(label), UnknownAttributeWarning)
+ else:
+ value = attributes[label]
+ setattr(canobj, canobjectlabel, value)
+ canobj.convertstate = 'xdd'
+
+