diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-01-03 12:33:09 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-01-03 13:56:16 +0000 |
commit | f4634b2caf1f92f27a507207ff181d3a7927871f (patch) | |
tree | 2d1567d69145244ad97cd76cc83d550184bbc63a /tools/xincludator.py | |
parent | 8058faf2407867dcda1aca35616dd23496b1b814 (diff) | |
download | telepathy-glib-f4634b2caf1f92f27a507207ff181d3a7927871f.tar.gz |
Make the code generation tools work under either Python 2 or 3
They have been verified to produce identical output in _gen.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=56758
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Xavier Claessens <xavier.claessens@collabora.co.uk>
Diffstat (limited to 'tools/xincludator.py')
-rw-r--r-- | tools/xincludator.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/tools/xincludator.py b/tools/xincludator.py index 63e106ace..f9ed49ce4 100644 --- a/tools/xincludator.py +++ b/tools/xincludator.py @@ -1,17 +1,19 @@ #!/usr/bin/python +import sys from sys import argv, stdout, stderr import codecs, locale import os import xml.dom.minidom -stdout = codecs.getwriter('utf-8')(stdout) +if sys.version_info[0] < 3: + stdout = codecs.getwriter('utf-8')(stdout) NS_XI = 'http://www.w3.org/2001/XInclude' def xincludate(dom, base, dropns = []): remove_attrs = [] - for i in xrange(dom.documentElement.attributes.length): + for i in range(dom.documentElement.attributes.length): attr = dom.documentElement.attributes.item(i) if attr.prefix == 'xmlns': if attr.localName in dropns: @@ -34,6 +36,11 @@ if __name__ == '__main__': argv = argv[1:] dom = xml.dom.minidom.parse(argv[0]) xincludate(dom, argv[0]) - xml = dom.toxml() + + if sys.version_info[0] >= 3: + xml = dom.toxml(encoding=None) + else: + xml = dom.toxml() + stdout.write(xml) stdout.write('\n') |