diff options
author | Florian Bruhin <me@the-compiler.org> | 2012-06-22 09:07:44 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2012-06-22 09:07:44 +0200 |
commit | b559c15509a4f5d746b97fe38bc35d90ee20caf4 (patch) | |
tree | bef84a68b82f4d1d058f8f2112e8bd4201d14d22 | |
parent | 34f01ec0f2b0c17da5357f7e8913adc08025d5ab (diff) | |
download | xdd2esi-b559c15509a4f5d746b97fe38bc35d90ee20caf4.tar.gz xdd2esi-b559c15509a4f5d746b97fe38bc35d90ee20caf4.zip |
Move _add_to_xml() and _get_info_tree() from method to function in esilib
-rw-r--r-- | esilib.py | 66 |
1 files changed, 33 insertions, 33 deletions
@@ -205,7 +205,7 @@ class ESIFile: ("Type", canobj.datatype), ("BitSize", esisize), ] - info = self._get_info_tree(canobj) + info = _get_info_tree(canobj) flags = [ ("Access", canobj.accesstype), ("Category", canobj.category), @@ -214,7 +214,7 @@ class ESIFile: ignored = [ ("objFlags setting (see CiA-306)", canobj.objflags) ] - obj = self._add_to_xml(self.objtree, "Object", properties, ignored) + obj = _add_to_xml(self.objtree, "Object", properties, ignored) if canobj.infocomment is not None: _append_comment(obj, canobj.infocomment) _append_elements(obj, "Info", info, force=True) @@ -241,7 +241,7 @@ class ESIFile: ignored = [ ("objFlags setting (see CiA-306)", canobj.objflags) ] - obj = self._add_to_xml(parent, "SubItem", properties, ignored) + obj = _add_to_xml(parent, "SubItem", properties, ignored) _append_elements(obj, "Flags", flags) self._set_bitoffset(parent, esiname, bitoffset, esisize) return parent @@ -255,7 +255,7 @@ class ESIFile: infotree = xmlobj.xpath('Info')[0] for subobj in canobj.subobjects: name = [('Name', subobj.name)] - info = self._get_info_tree(subobj) + info = _get_info_tree(subobj) if info is not None: subitem = _append_elements(infotree, "SubItem", name) _append_elements(subitem, "Info", info) @@ -290,35 +290,6 @@ class ESIFile: esisize = 'x' return esisize - def _add_to_xml(self, xmlparent, xmlnodename, properties, ignored): - """ Adds a new node with it's properties to the XML """ - obj = _append_elements(xmlparent, xmlnodename, properties) - for elem in ignored: - if elem[1] is not None: - _append_comment(obj, "ignored: {} (value: {})".format(elem[0], - elem[1])) - warnings.warn("Ignored attribute '{}' (value: {})".format( - elem[0], elem[1])) - return obj - - def _get_info_tree(self, canobj): - """ Returns the info-tree of an object """ - if getattr(canobj.sibling.datatype, 'type_', None) == 'octet': - return None - elif canobj.dataorvalue == "data": - info = [ - ("MinData", canobj.minimum), - ("MaxData", canobj.maximum), - ("DefaultData", canobj.default), - ] - elif canobj.dataorvalue == "value": - info = [ - ("MinValue", canobj.minimum), - ("MaxValue", canobj.maximum), - ("DefaultValue", canobj.default), - ] - return info - def type_to_esitype(datatype): """ Takes a py-datatype and returns the corresponding esi-type """ esitype = "" @@ -438,3 +409,32 @@ def _append_elements(root, subnode, attrs, force=False): else: retval = None return retval + +def _add_to_xml(xmlparent, xmlnodename, properties, ignored): + """ Adds a new node with it's properties to the XML """ + obj = _append_elements(xmlparent, xmlnodename, properties) + for elem in ignored: + if elem[1] is not None: + _append_comment(obj, "ignored: {} (value: {})".format(elem[0], + elem[1])) + warnings.warn("Ignored attribute '{}' (value: {})".format( + elem[0], elem[1])) + return obj + +def _get_info_tree(canobj): + """ Returns the info-tree of an object """ + if getattr(canobj.sibling.datatype, 'type_', None) == 'octet': + return None + elif canobj.dataorvalue == "data": + info = [ + ("MinData", canobj.minimum), + ("MaxData", canobj.maximum), + ("DefaultData", canobj.default), + ] + elif canobj.dataorvalue == "value": + info = [ + ("MinValue", canobj.minimum), + ("MaxValue", canobj.maximum), + ("DefaultValue", canobj.default), + ] + return info |