summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Dahlin <jdahlin@async.com.br>2008-06-07 12:39:35 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-06-07 12:39:35 +0000
commitd1927505c5f352d459e76f4cb6a67155ecbb549a (patch)
tree9a1c7be0e4652d49fe28d38c3572882ca284a399
parent4bd7483b630c9efc3ac509d241fd8a4946e1ee4d (diff)
downloadgobject-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
-rw-r--r--ChangeLog5
-rw-r--r--giscanner/xmlwriter.py38
2 files changed, 36 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 5af8e82f..64447ad6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-06-07 Johan Dahlin <jdahlin@async.com.br>
+
+ * giscanner/xmlwriter.py:
+ Improve line wrapping when > 79 charaters
+
2008-06-05 Jürg Billeter <j@bitron.ch>
* giscanner/ast.py:
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()