diff options
author | Dieter Verfaillie <dieterv@optionexplicit.be> | 2013-09-11 12:55:25 +0200 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-10-09 12:48:45 -0400 |
commit | f345916405d94829696985479eff3a5836e9b1f6 (patch) | |
tree | 095d81567506b683b7fcec8855db282f664260b4 | |
parent | d0c2f49a87a9b8db6aaed367544fabd612b0dc0b (diff) | |
download | gobject-introspection-f345916405d94829696985479eff3a5836e9b1f6.tar.gz |
giscanner: remove Python xml attribute formatter
There's no sense in keeping it around as it is never
used. And even though measuring the time it takes to
build Gtk-3.0.gir using a) the C version and b) the
Python version reveals there is no measurable difference
to speak of (when *not* running under Python's cProfile
module):
With C collect_attributes:
==========================
real 0m30.614s
real 0m32.255s
real 0m31.034s
With Python collect_attributes:
===============================
real 0m31.530s
real 0m31.549s
real 0m31.673s
The C version ends up using g_markup_escape_text() which
will escape \004 as . Even though this is invalid
xml 1.0 (but valid xml 1.1), the Python version leaves
the \004 as is, which is even less desirable...
-rwxr-xr-x | giscanner/xmlwriter.py | 49 |
1 files changed, 5 insertions, 44 deletions
diff --git a/giscanner/xmlwriter.py b/giscanner/xmlwriter.py index 6efe684d..5fdcffed 100755 --- a/giscanner/xmlwriter.py +++ b/giscanner/xmlwriter.py @@ -24,48 +24,16 @@ import os from contextlib import contextmanager from cStringIO import StringIO -from xml.sax.saxutils import escape, quoteattr +from xml.sax.saxutils import escape from .libtoolimporter import LibtoolImporter -def _calc_attrs_length(attributes, indent, self_indent): - if indent == -1: - return -1 - attr_length = 0 - for attr, value in attributes: - # FIXME: actually, if we have attributes with None as value this - # should be considered a bug and raise an error. We are just - # ignoring them here while we fix GIRParser to create the right - # ast with the correct attributes. - if value is None: - continue - attr_length += 2 + len(attr) + len(quoteattr(value)) - return attr_length + indent + self_indent - - -def collect_attributes(tag_name, attributes, self_indent, self_indent_char, indent=-1): - if not attributes: - return '' - if _calc_attrs_length(attributes, indent, self_indent) > 79: - indent_len = self_indent + len(tag_name) + 1 +with LibtoolImporter(None, None): + if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ: + from _giscanner import collect_attributes else: - indent_len = 0 - first = True - attr_value = '' - for attr, value in attributes: - # FIXME: actually, if we have attributes with None as value this - # should be considered a bug and raise an error. We are just - # ignoring them here while we fix GIRParser to create the right - # ast with the correct attributes. - if value is None: - continue - if indent_len and not first: - attr_value += '\n%s' % (self_indent_char * indent_len) - attr_value += ' %s=%s' % (attr, quoteattr(value)) - if first: - first = False - return attr_value + from giscanner._giscanner import collect_attributes def build_xml_tag(tag_name, attributes=None, data=None, self_indent=0, @@ -87,13 +55,6 @@ def build_xml_tag(tag_name, attributes=None, data=None, self_indent=0, return prefix + attrs + suffix -with LibtoolImporter(None, None): - if 'UNINSTALLED_INTROSPECTION_SRCDIR' in os.environ: - from _giscanner import collect_attributes - else: - from giscanner._giscanner import collect_attributes - - class XMLWriter(object): def __init__(self): |