diff options
author | Johan Dahlin <jdahlin@async.com.br> | 2008-06-07 12:39:35 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-06-07 12:39:35 +0000 |
commit | d1927505c5f352d459e76f4cb6a67155ecbb549a (patch) | |
tree | 9a1c7be0e4652d49fe28d38c3572882ca284a399 /giscanner/xmlwriter.py | |
parent | 4bd7483b630c9efc3ac509d241fd8a4946e1ee4d (diff) | |
download | gobject-introspection-d1927505c5f352d459e76f4cb6a67155ecbb549a.tar.gz |
Improve line wrapping when > 79 charaters
2008-06-07 Johan Dahlin <jdahlin@async.com.br>
* giscanner/xmlwriter.py:
Improve line wrapping when > 79 charaters
svn path=/trunk/; revision=286
Diffstat (limited to 'giscanner/xmlwriter.py')
-rw-r--r-- | giscanner/xmlwriter.py | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/giscanner/xmlwriter.py b/giscanner/xmlwriter.py index cbbbcbeb..6c187a12 100644 --- a/giscanner/xmlwriter.py +++ b/giscanner/xmlwriter.py @@ -42,14 +42,13 @@ class XMLWriter(object): raise ValueError( "value for attribute %r cannot be None" % (attr,)) attr_length += 2 + len(attr) + len(quoteattr(value)) - return attr_length + indent + return attr_length + indent + self._indent - def _collect_attributes(self, attributes, extra_indent=-1): + def _collect_attributes(self, tag_name, attributes, indent=-1): if not attributes: return '' - extra_indent += len(self._indent_char) * self._indent - if self._calc_attrs_length(attributes, extra_indent) > 79: - indent_len = extra_indent + if self._calc_attrs_length(attributes, indent) > 79: + indent_len = self._indent + len(tag_name) + 1 else: indent_len = 0 first = True @@ -67,7 +66,7 @@ class XMLWriter(object): def _open_tag(self, tag_name, attributes=None): attrs = self._collect_attributes( - attributes, len(tag_name) + 1) + tag_name, attributes, len(tag_name) + 2) self.write_line('<%s%s>' % (tag_name, attrs)) def _close_tag(self, tag_name): @@ -82,13 +81,15 @@ class XMLWriter(object): self._data.write('%s%s\n' % (self._indent_char * self._indent, line)) def write_tag(self, tag_name, attributes, data=None): + if attributes is None: + attributes = [] prefix = '<%s' % (tag_name,) if data is not None: suffix = '>%s</%s>' % (data, tag_name) else: suffix = '/>' attrs = self._collect_attributes( - attributes, len(prefix) + len(suffix)) + tag_name, attributes, len(prefix) + len(suffix)) self.write_line(prefix + attrs + suffix) def push_tag(self, tag_name, attributes=None): @@ -110,3 +111,26 @@ class XMLWriter(object): finally: self.pop_tag() + +def test(): + w = XMLWriter() + w.push_tag('repository') + w.push_tag('namespace') + w.push_tag('enumeration') + w.push_tag('member', + [('name', 'west'), + ('value', '7'), + ('c:identifier', 'GTK_ANCHOR_WEST'), + ('glib:nick', 'west')]) + + w.pop_tag() + w.pop_tag() + w.pop_tag() + x = w.get_xml() + lines = x.split('\n') + import pprint + pprint.pprint(lines) + assert len(lines[3]) < 80, len(lines[3]) + +if __name__ == '__main__': + test() |