summaryrefslogtreecommitdiff
path: root/giscanner/xmlwriter.py
diff options
context:
space:
mode:
Diffstat (limited to 'giscanner/xmlwriter.py')
-rwxr-xr-xgiscanner/xmlwriter.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/giscanner/xmlwriter.py b/giscanner/xmlwriter.py
index fb34adf1..11f84859 100755
--- a/giscanner/xmlwriter.py
+++ b/giscanner/xmlwriter.py
@@ -68,6 +68,23 @@ def collect_attributes(tag_name, attributes, self_indent,
first = False
return attr_value
+def build_xml_tag(tag_name, attributes=None, data=None, self_indent=0,
+ self_indent_char=' '):
+ if attributes is None:
+ attributes = []
+ prefix = u'<%s' % (tag_name, )
+ if data is not None:
+ if isinstance(data, str):
+ data = data.decode('UTF-8')
+ suffix = u'>%s</%s>' % (escape(data), tag_name)
+ else:
+ suffix = u'/>'
+ attrs = collect_attributes(
+ tag_name, attributes,
+ self_indent,
+ self_indent_char,
+ len(prefix) + len(suffix))
+ return prefix + attrs + suffix
with LibtoolImporter(None, None):
if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ:
@@ -131,21 +148,8 @@ class XMLWriter(object):
self.write_line('<!-- %s -->' % (text, ))
def write_tag(self, tag_name, attributes, data=None):
- if attributes is None:
- attributes = []
- prefix = u'<%s' % (tag_name, )
- if data is not None:
- if isinstance(data, str):
- data = data.decode('UTF-8')
- suffix = u'>%s</%s>' % (escape(data), tag_name)
- else:
- suffix = u'/>'
- attrs = collect_attributes(
- tag_name, attributes,
- self._indent,
- self._indent_char,
- len(prefix) + len(suffix))
- self.write_line(prefix + attrs + suffix)
+ self.write_line(build_xml_tag(tag_name, attributes, data,
+ self._indent, self._indent_char))
def push_tag(self, tag_name, attributes=None):
if attributes is None: