summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-06-22 08:29:47 +0200
committerFlorian Bruhin <me@the-compiler.org>2012-06-22 08:29:47 +0200
commit1c870f3f6ed0905193e398c01c54c0de06aa2ab1 (patch)
treed82c358f681942b8e658e1519a5668fd6abaa071
parentd80f05276dd2b265dbd3e86fe766bde7243f6892 (diff)
downloadxdd2esi-1c870f3f6ed0905193e398c01c54c0de06aa2ab1.tar.gz
xdd2esi-1c870f3f6ed0905193e398c01c54c0de06aa2ab1.zip
Make _append_comment a function, not a method
-rw-r--r--esilib.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/esilib.py b/esilib.py
index 448878a..ff10f9f 100644
--- a/esilib.py
+++ b/esilib.py
@@ -50,7 +50,7 @@ class ESIFile:
self.dicttree = etree.Element("Dictionary")
infoline = "Generated by {} on {}".format(versioninfo,
datetime.datetime.now().ctime())
- self._append_comment(self.dicttree, infoline)
+ _append_comment(self.dicttree, infoline)
self.dt_simple = etree.Element("DataTypes")
self.dt_middle = etree.Element("DataTypes")
self.dt_complex = etree.Element("DataTypes")
@@ -140,7 +140,7 @@ class ESIFile:
(esitype, esisize) = type_to_esitype(datatype)
if esitype not in self.bitsizes: # Datatype does not already exist
properties = [("Name", esitype), ("BitSize", esisize)]
- self._append_comment(self.dt_simple, esitype)
+ _append_comment(self.dt_simple, esitype)
self._append_elements(self.dt_simple, "DataType", properties)
self.bitsizes[esitype] = esisize
return (esitype, esisize)
@@ -153,7 +153,7 @@ class ESIFile:
"""
# Bitsize will be set later
properties = [ ("Name", esiname), ("BitSize", 'x') ]
- self._append_comment(self.dt_complex, esiname)
+ _append_comment(self.dt_complex, esiname)
record = self._append_elements(self.dt_complex, "DataType",
properties)
return record
@@ -182,7 +182,7 @@ class ESIFile:
("BitSize", bitsize),
]
arrayinfo = [ ("LBound", lbound), ("Elements", elements) ]
- self._append_comment(target, esiname)
+ _append_comment(target, esiname)
array = self._append_elements(target, "DataType", properties)
self._append_elements(array, "ArrayInfo", arrayinfo)
self.bitsizes[esiname] = bitsize
@@ -193,7 +193,7 @@ class ESIFile:
def add_object(self, canobj):
""" Adds a new object to the tree """
- self._append_comment(self.objtree, canobj.index)
+ _append_comment(self.objtree, canobj.index)
if canobj.index in self.added_objs:
warnings.warn("Object {} already exists!".format(canobj.index),
DoubleIndexWarning)
@@ -217,7 +217,7 @@ class ESIFile:
]
obj = self._add_to_xml(self.objtree, "Object", properties, ignored)
if canobj.infocomment is not None:
- self._append_comment(obj, canobj.infocomment)
+ _append_comment(obj, canobj.infocomment)
self._append_elements(obj, "Info", info, force=True)
self._append_elements(obj, "Flags", flags)
return obj
@@ -296,8 +296,8 @@ class ESIFile:
obj = self._append_elements(xmlparent, xmlnodename, properties)
for elem in ignored:
if elem[1] is not None:
- self._append_comment(obj, "ignored: {} (value: {})".format(
- elem[0], elem[1]))
+ _append_comment(obj, "ignored: {} (value: {})".format(elem[0],
+ elem[1]))
warnings.warn("Ignored attribute '{}' (value: {})".format(
elem[0], elem[1]))
return obj
@@ -440,3 +440,7 @@ def _esitype_oct(datatype):
esibasetype = type_to_esitype(pybasetype)[0]
esitype = "ARRAY [0..{}] OF {}".format(esilength - 1, esibasetype)
return (esitype, esisize)
+
+def _append_comment(root, comment):
+ """ Appends a comment to the tree """
+ root.append(etree.Comment(comment))