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>
Simon McVittie
11 years ago
2 | 2 | from sys import argv, stdout, stderr |
3 | 3 | import xml.dom.minidom |
4 | 4 | |
5 | from libtpcodegen import file_set_contents | |
5 | from libtpcodegen import file_set_contents, u | |
6 | 6 | from libglibcodegen import NS_TP, get_docstring, \ |
7 | 7 | get_descendant_text, get_by_path |
8 | 8 | |
11 | 11 | self.prefix = prefix + '_' |
12 | 12 | self.spec = get_by_path(dom, "spec")[0] |
13 | 13 | |
14 | self.output_base = output_base | |
14 | self.output_base = output_base | |
15 | 15 | self.__header = [] |
16 | 16 | self.__docs = [] |
17 | 17 | |
20 | 20 | self.do_body() |
21 | 21 | self.do_footer() |
22 | 22 | |
23 | file_set_contents(self.output_base + '.h', ''.join(self.__header)) | |
24 | file_set_contents(self.output_base + '-gtk-doc.h', ''.join(self.__docs)) | |
23 | file_set_contents(self.output_base + '.h', u('').join(self.__header).encode('utf-8')) | |
24 | file_set_contents(self.output_base + '-gtk-doc.h', u('').join(self.__docs).encode('utf-8')) | |
25 | 25 | |
26 | 26 | def write(self, code): |
27 | self.__header.append(code.encode('utf-8')) | |
27 | self.__header.append(code) | |
28 | 28 | |
29 | 29 | def d(self, code): |
30 | self.__docs.append(code.encode('utf-8')) | |
30 | self.__docs.append(code) | |
31 | 31 | |
32 | 32 | # Header |
33 | 33 | def do_header(self): |
26 | 26 | import xml.dom.minidom |
27 | 27 | from getopt import gnu_getopt |
28 | 28 | |
29 | from libtpcodegen import file_set_contents | |
30 | from libglibcodegen import Signature, type_to_gtype, cmp_by_name, \ | |
29 | from libtpcodegen import file_set_contents, key_by_name, u | |
30 | from libglibcodegen import Signature, type_to_gtype, \ | |
31 | 31 | get_docstring, xml_escape, get_deprecated |
32 | 32 | |
33 | 33 | |
73 | 73 | self.guard = opts.get('--guard', None) |
74 | 74 | |
75 | 75 | def h(self, s): |
76 | if isinstance(s, unicode): | |
77 | s = s.encode('utf-8') | |
78 | 76 | self.__header.append(s) |
79 | 77 | |
80 | 78 | def b(self, s): |
81 | if isinstance(s, unicode): | |
82 | s = s.encode('utf-8') | |
83 | 79 | self.__body.append(s) |
84 | 80 | |
85 | 81 | def d(self, s): |
86 | if isinstance(s, unicode): | |
87 | s = s.encode('utf-8') | |
88 | 82 | self.__docs.append(s) |
89 | 83 | |
90 | 84 | def get_iface_quark(self): |
1190 | 1184 | self.b('') |
1191 | 1185 | |
1192 | 1186 | nodes = self.dom.getElementsByTagName('node') |
1193 | nodes.sort(cmp_by_name) | |
1187 | nodes.sort(key=key_by_name) | |
1194 | 1188 | |
1195 | 1189 | for node in nodes: |
1196 | 1190 | self.do_interface(node) |
1243 | 1237 | self.h('#endif /* defined (%s) */' % self.guard) |
1244 | 1238 | self.h('') |
1245 | 1239 | |
1246 | file_set_contents(self.basename + '.h', '\n'.join(self.__header)) | |
1247 | file_set_contents(self.basename + '-body.h', '\n'.join(self.__body)) | |
1248 | file_set_contents(self.basename + '-gtk-doc.h', '\n'.join(self.__docs)) | |
1240 | file_set_contents(self.basename + '.h', u('\n').join(self.__header).encode('utf-8')) | |
1241 | file_set_contents(self.basename + '-body.h', u('\n').join(self.__body).encode('utf-8')) | |
1242 | file_set_contents(self.basename + '-gtk-doc.h', u('\n').join(self.__docs).encode('utf-8')) | |
1249 | 1243 | |
1250 | 1244 | def types_to_gtypes(types): |
1251 | 1245 | return [type_to_gtype(t)[1] for t in types] |
30 | 30 | for signal in signals: |
31 | 31 | self.do_signal(signal) |
32 | 32 | |
33 | print 'void' | |
34 | print '%s_register_dbus_glib_marshallers (void)' % self.prefix | |
35 | print '{' | |
33 | print('void') | |
34 | print('%s_register_dbus_glib_marshallers (void)' % self.prefix) | |
35 | print('{') | |
36 | 36 | |
37 | all = self.marshallers.keys() | |
37 | all = list(self.marshallers.keys()) | |
38 | 38 | all.sort() |
39 | 39 | for marshaller in all: |
40 | 40 | rhs = self.marshallers[marshaller] |
41 | 41 | |
42 | print ' dbus_g_object_register_marshaller (' | |
43 | print ' g_cclosure_marshal_generic,' | |
44 | print ' G_TYPE_NONE, /* return */' | |
42 | print(' dbus_g_object_register_marshaller (') | |
43 | print(' g_cclosure_marshal_generic,') | |
44 | print(' G_TYPE_NONE, /* return */') | |
45 | 45 | for type in rhs: |
46 | print ' G_TYPE_%s,' % type.replace('VOID', 'NONE') | |
47 | print ' G_TYPE_INVALID);' | |
46 | print(' G_TYPE_%s,' % type.replace('VOID', 'NONE')) | |
47 | print(' G_TYPE_INVALID);') | |
48 | 48 | |
49 | print '}' | |
49 | print('}') | |
50 | 50 | |
51 | 51 | |
52 | 52 | def types_to_gtypes(types): |
11 | 11 | |
12 | 12 | def __call__(self): |
13 | 13 | |
14 | print '{' | |
15 | print ' GEnumClass *klass;' | |
16 | print ' GEnumValue *value_by_name;' | |
17 | print ' GEnumValue *value_by_nick;' | |
18 | print '' | |
19 | print ' g_type_init ();' | |
20 | print ' klass = g_type_class_ref (TP_TYPE_ERROR);' | |
14 | print('{') | |
15 | print(' GEnumClass *klass;') | |
16 | print(' GEnumValue *value_by_name;') | |
17 | print(' GEnumValue *value_by_nick;') | |
18 | print('') | |
19 | print(' g_type_init ();') | |
20 | print(' klass = g_type_class_ref (TP_TYPE_ERROR);') | |
21 | 21 | |
22 | 22 | for error in self.errors.getElementsByTagNameNS(NS_TP, 'error'): |
23 | 23 | ns = error.parentNode.getAttribute('namespace') |
27 | 27 | s = ('TP_ERROR_STR_' + |
28 | 28 | error.getAttribute('name').replace(' ', '_').replace('.', '_').upper()) |
29 | 29 | |
30 | print '' | |
31 | print ' /* %s.%s */' % (ns, nick) | |
32 | print (' value_by_name = g_enum_get_value_by_name (klass, "%s");' | |
33 | % enum) | |
34 | print (' value_by_nick = g_enum_get_value_by_nick (klass, "%s");' | |
35 | % nick) | |
36 | print (' g_assert (value_by_name != NULL);') | |
37 | print (' g_assert (value_by_nick != NULL);') | |
38 | print (' g_assert_cmpint (value_by_name->value, ==, %s);' | |
39 | % enum) | |
40 | print (' g_assert_cmpint (value_by_nick->value, ==, %s);' | |
41 | % enum) | |
42 | print (' g_assert_cmpstr (value_by_name->value_name, ==, "%s");' | |
43 | % enum) | |
44 | print (' g_assert_cmpstr (value_by_nick->value_name, ==, "%s");' | |
45 | % enum) | |
46 | print (' g_assert_cmpstr (value_by_name->value_nick, ==, "%s");' | |
47 | % nick) | |
48 | print (' g_assert_cmpstr (value_by_nick->value_nick, ==, "%s");' | |
49 | % nick) | |
50 | print (' g_assert_cmpstr (%s, ==, TP_ERROR_PREFIX ".%s");' | |
51 | % (s, nick)) | |
30 | print('') | |
31 | print(' /* %s.%s */' % (ns, nick)) | |
32 | print(' value_by_name = g_enum_get_value_by_name (klass, "%s");' | |
33 | % enum) | |
34 | print(' value_by_nick = g_enum_get_value_by_nick (klass, "%s");' | |
35 | % nick) | |
36 | print(' g_assert (value_by_name != NULL);') | |
37 | print(' g_assert (value_by_nick != NULL);') | |
38 | print(' g_assert_cmpint (value_by_name->value, ==, %s);' | |
39 | % enum) | |
40 | print(' g_assert_cmpint (value_by_nick->value, ==, %s);' | |
41 | % enum) | |
42 | print(' g_assert_cmpstr (value_by_name->value_name, ==, "%s");' | |
43 | % enum) | |
44 | print(' g_assert_cmpstr (value_by_nick->value_name, ==, "%s");' | |
45 | % enum) | |
46 | print(' g_assert_cmpstr (value_by_name->value_nick, ==, "%s");' | |
47 | % nick) | |
48 | print(' g_assert_cmpstr (value_by_nick->value_nick, ==, "%s");' | |
49 | % nick) | |
50 | print(' g_assert_cmpstr (%s, ==, TP_ERROR_PREFIX ".%s");' | |
51 | % (s, nick)) | |
52 | 52 | |
53 | print '}' | |
53 | print('}') | |
54 | 54 | |
55 | 55 | if __name__ == '__main__': |
56 | 56 | argv = sys.argv[1:] |
2 | 2 | import sys |
3 | 3 | import xml.dom.minidom |
4 | 4 | |
5 | from libtpcodegen import file_set_contents | |
5 | from libtpcodegen import file_set_contents, u | |
6 | 6 | from libglibcodegen import NS_TP, get_docstring, xml_escape |
7 | 7 | |
8 | 8 | class Generator(object): |
16 | 16 | self.__docs = [] |
17 | 17 | |
18 | 18 | def h(self, s): |
19 | if isinstance(s, unicode): | |
20 | s = s.encode('utf-8') | |
21 | 19 | self.__header.append(s) |
22 | 20 | |
23 | 21 | def b(self, s): |
24 | if isinstance(s, unicode): | |
25 | s = s.encode('utf-8') | |
26 | 22 | self.__body.append(s) |
27 | 23 | |
28 | 24 | def d(self, s): |
29 | if isinstance(s, unicode): | |
30 | s = s.encode('utf-8') | |
31 | 25 | self.__docs.append(s) |
32 | 26 | |
33 | 27 | def __call__(self): |
71 | 65 | self.h('') |
72 | 66 | self.b('') |
73 | 67 | |
74 | file_set_contents(self.basename + '.h', '\n'.join(self.__header)) | |
75 | file_set_contents(self.basename + '.c', '\n'.join(self.__body)) | |
76 | file_set_contents(self.basename + '-gtk-doc.h', '\n'.join(self.__docs)) | |
68 | file_set_contents(self.basename + '.h', u('\n').join(self.__header).encode('utf-8')) | |
69 | file_set_contents(self.basename + '.c', u('\n').join(self.__body).encode('utf-8')) | |
70 | file_set_contents(self.basename + '-gtk-doc.h', u('\n').join(self.__docs).encode('utf-8')) | |
77 | 71 | |
78 | 72 | if __name__ == '__main__': |
79 | 73 | argv = sys.argv[1:] |
25 | 25 | import os.path |
26 | 26 | import xml.dom.minidom |
27 | 27 | |
28 | from libtpcodegen import file_set_contents | |
29 | from libglibcodegen import Signature, type_to_gtype, cmp_by_name, \ | |
28 | from libtpcodegen import file_set_contents, key_by_name, u | |
29 | from libglibcodegen import Signature, type_to_gtype, \ | |
30 | 30 | NS_TP, dbus_gutils_wincaps_to_uscore |
31 | 31 | |
32 | 32 | |
84 | 84 | self.allow_havoc = allow_havoc |
85 | 85 | |
86 | 86 | def h(self, s): |
87 | if isinstance(s, unicode): | |
88 | s = s.encode('utf-8') | |
89 | 87 | self.__header.append(s) |
90 | 88 | |
91 | 89 | def b(self, s): |
92 | if isinstance(s, unicode): | |
93 | s = s.encode('utf-8') | |
94 | 90 | self.__body.append(s) |
95 | 91 | |
96 | 92 | def d(self, s): |
97 | if isinstance(s, unicode): | |
98 | s = s.encode('utf-8') | |
99 | 93 | self.__docs.append(s) |
100 | 94 | |
101 | 95 | def do_node(self, node): |
732 | 726 | |
733 | 727 | def __call__(self): |
734 | 728 | nodes = self.dom.getElementsByTagName('node') |
735 | nodes.sort(cmp_by_name) | |
729 | nodes.sort(key=key_by_name) | |
736 | 730 | |
737 | 731 | self.h('#include <glib-object.h>') |
738 | 732 | self.h('#include <dbus/dbus-glib.h>') |
760 | 754 | |
761 | 755 | self.h('') |
762 | 756 | self.b('') |
763 | file_set_contents(self.basename + '.h', '\n'.join(self.__header)) | |
764 | file_set_contents(self.basename + '.c', '\n'.join(self.__body)) | |
765 | file_set_contents(self.basename + '-gtk-doc.h', '\n'.join(self.__docs)) | |
757 | file_set_contents(self.basename + '.h', u('\n').join(self.__header).encode('utf-8')) | |
758 | file_set_contents(self.basename + '.c', u('\n').join(self.__body).encode('utf-8')) | |
759 | file_set_contents(self.basename + '-gtk-doc.h', u('\n').join(self.__docs).encode('utf-8')) | |
766 | 760 | |
767 | 761 | def cmdline_error(): |
768 | print """\ | |
762 | print("""\ | |
769 | 763 | usage: |
770 | 764 | gen-ginterface [OPTIONS] xmlfile Prefix_ |
771 | 765 | options: |
785 | 779 | void symbol (DBusGMethodInvocation *context) |
786 | 780 | and return some sort of "not implemented" error via |
787 | 781 | dbus_g_method_return_error (context, ...) |
788 | """ | |
782 | """) | |
789 | 783 | sys.exit(1) |
790 | 784 | |
791 | 785 |
22 | 22 | import sys |
23 | 23 | import xml.dom.minidom |
24 | 24 | |
25 | from libtpcodegen import file_set_contents | |
25 | from libtpcodegen import file_set_contents, u | |
26 | 26 | from libglibcodegen import escape_as_identifier, \ |
27 | 27 | get_docstring, \ |
28 | 28 | NS_TP, \ |
67 | 67 | self.need_other_arrays = {} |
68 | 68 | |
69 | 69 | def h(self, code): |
70 | self.header.append(code.encode("utf-8")) | |
70 | self.header.append(code) | |
71 | 71 | |
72 | 72 | def c(self, code): |
73 | self.body.append(code.encode("utf-8")) | |
73 | self.body.append(code) | |
74 | 74 | |
75 | 75 | def d(self, code): |
76 | self.docs.append(code.encode('utf-8')) | |
76 | self.docs.append(code) | |
77 | 77 | |
78 | 78 | def do_mapping_header(self, mapping): |
79 | 79 | members = mapping.getElementsByTagNameNS(NS_TP, 'member') |
291 | 291 | self.c(' return t;\n') |
292 | 292 | self.c('}\n\n') |
293 | 293 | |
294 | file_set_contents(self.output + '.h', ''.join(self.header)) | |
295 | file_set_contents(self.output + '-body.h', ''.join(self.body)) | |
296 | file_set_contents(self.output + '-gtk-doc.h', ''.join(self.docs)) | |
294 | file_set_contents(self.output + '.h', u('').join(self.header).encode('utf-8')) | |
295 | file_set_contents(self.output + '-body.h', u('').join(self.body).encode('utf-8')) | |
296 | file_set_contents(self.output + '-gtk-doc.h', u('').join(self.docs).encode('utf-8')) | |
297 | 297 | |
298 | 298 | if __name__ == '__main__': |
299 | 299 | argv = sys.argv[1:] |
2 | 2 | from sys import argv, stdout, stderr |
3 | 3 | import xml.dom.minidom |
4 | 4 | |
5 | from libtpcodegen import file_set_contents | |
5 | from libtpcodegen import file_set_contents, u | |
6 | 6 | from libglibcodegen import NS_TP, get_docstring, \ |
7 | 7 | get_descendant_text, get_by_path |
8 | 8 | |
23 | 23 | self.spec = get_by_path(dom, "spec")[0] |
24 | 24 | |
25 | 25 | def h(self, code): |
26 | self.decls.append(code.encode('utf-8')) | |
26 | self.decls.append(code) | |
27 | 27 | |
28 | 28 | def c(self, code): |
29 | self.impls.append(code.encode('utf-8')) | |
29 | self.impls.append(code) | |
30 | 30 | |
31 | 31 | def d(self, code): |
32 | self.docs.append(code.encode('utf-8')) | |
32 | self.docs.append(code) | |
33 | 33 | |
34 | 34 | def __call__(self): |
35 | 35 | for f in self.h, self.c: |
36 | 36 | self.do_header(f) |
37 | 37 | self.do_body() |
38 | 38 | |
39 | file_set_contents(self.implfile, ''.join(self.impls)) | |
40 | file_set_contents(self.declfile, ''.join(self.decls)) | |
41 | file_set_contents(self.docfile, ''.join(self.docs)) | |
39 | file_set_contents(self.implfile, u('').join(self.impls).encode('utf-8')) | |
40 | file_set_contents(self.declfile, u('').join(self.decls).encode('utf-8')) | |
41 | file_set_contents(self.docfile, u('').join(self.docs).encode('utf-8')) | |
42 | 42 | |
43 | 43 | # Header |
44 | 44 | def do_header(self, f): |
86 | 86 | |
87 | 87 | head, tail = argv |
88 | 88 | |
89 | print '\n'.join(gobject_header(head, tail, as_interface=as_interface)) | |
89 | print('\n'.join(gobject_header(head, tail, as_interface=as_interface))) |
153 | 153 | return ("GHashTable *", "DBUS_TYPE_G_STRING_STRING_HASHTABLE", "BOXED", False) |
154 | 154 | elif s[:2] == 'a{': #some arbitrary hash tables |
155 | 155 | if s[2] not in ('y', 'b', 'n', 'q', 'i', 'u', 's', 'o', 'g'): |
156 | raise Exception, "can't index a hashtable off non-basic type " + s | |
156 | raise Exception("can't index a hashtable off non-basic type " + s) | |
157 | 157 | first = type_to_gtype(s[2]) |
158 | 158 | second = type_to_gtype(s[3:-1]) |
159 | 159 | return ("GHashTable *", "(dbus_g_type_get_map (\"GHashTable\", " + first[1] + ", " + second[1] + "))", "BOXED", False) |
168 | 168 | return ("GValueArray *", gtype, "BOXED", True) |
169 | 169 | |
170 | 170 | # we just don't know .. |
171 | raise Exception, "don't know the GType for " + s | |
171 | raise Exception("don't know the GType for " + s) |
20 | 20 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
21 | 21 | |
22 | 22 | import os |
23 | import sys | |
23 | 24 | from string import ascii_letters, digits |
24 | 25 | |
25 | 26 | |
26 | 27 | NS_TP = "http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0" |
27 | 28 | |
28 | 29 | _ASCII_ALNUM = ascii_letters + digits |
30 | ||
31 | if sys.version_info[0] >= 3: | |
32 | def u(s): | |
33 | """Return s, which must be a str literal with no non-ASCII characters. | |
34 | This is like a more restricted form of the Python 2 u'' syntax. | |
35 | """ | |
36 | return s.encode('ascii').decode('ascii') | |
37 | else: | |
38 | def u(s): | |
39 | """Return a Unicode version of s, which must be a str literal | |
40 | (a bytestring) in which each byte is an ASCII character. | |
41 | This is like a more restricted form of the u'' syntax. | |
42 | """ | |
43 | return s.decode('ascii') | |
29 | 44 | |
30 | 45 | def file_set_contents(filename, contents): |
31 | 46 | try: |
37 | 52 | except OSError: |
38 | 53 | pass |
39 | 54 | |
40 | open(filename + '.tmp', 'w').write(contents) | |
55 | open(filename + '.tmp', 'wb').write(contents) | |
41 | 56 | os.rename(filename + '.tmp', filename) |
42 | 57 | |
43 | 58 | def cmp_by_name(node1, node2): |
44 | 59 | return cmp(node1.getAttributeNode("name").nodeValue, |
45 | 60 | node2.getAttributeNode("name").nodeValue) |
46 | 61 | |
62 | def key_by_name(node): | |
63 | return node.getAttributeNode("name").nodeValue | |
47 | 64 | |
48 | 65 | def escape_as_identifier(identifier): |
49 | 66 | """Escape the given string to be a valid D-Bus object path or service |
167 | 184 | self.remaining = string |
168 | 185 | |
169 | 186 | def next(self): |
187 | return self.__next__() | |
188 | ||
189 | def __next__(self): | |
170 | 190 | if self.remaining == '': |
171 | 191 | raise StopIteration |
172 | 192 |
62 | 62 | |
63 | 63 | if dpkg: |
64 | 64 | assert dpkg_first_line is not None |
65 | print dpkg_first_line | |
65 | print(dpkg_first_line) | |
66 | 66 | if dpkg_build_depends_package is not None: |
67 | print "* Build-Depends-Package: %s" % dpkg_build_depends_package | |
67 | print("* Build-Depends-Package: %s" % dpkg_build_depends_package) | |
68 | 68 | |
69 | 69 | for filename in abifiles: |
70 | 70 | lines = open(filename, 'r').readlines() |
119 | 119 | lines = lines[cut:] |
120 | 120 | |
121 | 121 | if gnuld: |
122 | print "%s {" % version | |
123 | print " global:" | |
122 | print("%s {" % version) | |
123 | print(" global:") | |
124 | 124 | |
125 | 125 | for symbol in lines: |
126 | 126 | symbol = symbol.strip() |
129 | 129 | continue |
130 | 130 | |
131 | 131 | if gnuld: |
132 | print " %s;" % symbol | |
132 | print(" %s;" % symbol) | |
133 | 133 | elif dpkg: |
134 | 134 | dpkg_symbols.append('%s@%s %s' % (symbol, version, release)) |
135 | 135 | |
141 | 141 | |
142 | 142 | if gnuld: |
143 | 143 | if extends == '-': |
144 | print " local:" | |
145 | print " *;" | |
146 | print "};" | |
144 | print(" local:") | |
145 | print(" *;") | |
146 | print("};") | |
147 | 147 | else: |
148 | print "} %s;" % extends | |
149 | ||
148 | print("} %s;" % extends) | |
149 | print("") | |
150 | 150 | |
151 | 151 | if dpkg: |
152 | 152 | dpkg_symbols.sort() |
153 | 153 | dpkg_versions.sort() |
154 | 154 | |
155 | 155 | for x in dpkg_versions: |
156 | print " %s" % x | |
156 | print(" %s" % x) | |
157 | 157 | |
158 | 158 | for x in dpkg_symbols: |
159 | print " %s" % x | |
159 | print(" %s" % x) | |
160 | 160 | |
161 | 161 | if symbol_set is not None: |
162 | 162 | missing = versioned_symbols - symbol_set |
181 | 181 | raise SystemExit(1) |
182 | 182 | |
183 | 183 | if gnuld: |
184 | print "%s {" % unreleased_version | |
185 | print " global:" | |
184 | print("%s {" % unreleased_version) | |
185 | print(" global:") | |
186 | 186 | |
187 | 187 | for symbol in unreleased: |
188 | print " %s;" % symbol | |
189 | ||
190 | print "} %s;" % version | |
188 | print(" %s;" % symbol) | |
189 | ||
190 | print("} %s;" % version) | |
191 | 191 | |
192 | 192 | |
193 | 193 | if __name__ == '__main__': |
0 | 0 | #!/usr/bin/python |
1 | 1 | |
2 | import sys | |
2 | 3 | from sys import argv, stdout, stderr |
3 | 4 | import codecs, locale |
4 | 5 | import os |
5 | 6 | import xml.dom.minidom |
6 | 7 | |
7 | stdout = codecs.getwriter('utf-8')(stdout) | |
8 | if sys.version_info[0] < 3: | |
9 | stdout = codecs.getwriter('utf-8')(stdout) | |
8 | 10 | |
9 | 11 | NS_XI = 'http://www.w3.org/2001/XInclude' |
10 | 12 | |
11 | 13 | def xincludate(dom, base, dropns = []): |
12 | 14 | remove_attrs = [] |
13 | for i in xrange(dom.documentElement.attributes.length): | |
15 | for i in range(dom.documentElement.attributes.length): | |
14 | 16 | attr = dom.documentElement.attributes.item(i) |
15 | 17 | if attr.prefix == 'xmlns': |
16 | 18 | if attr.localName in dropns: |
33 | 35 | argv = argv[1:] |
34 | 36 | dom = xml.dom.minidom.parse(argv[0]) |
35 | 37 | xincludate(dom, argv[0]) |
36 | xml = dom.toxml() | |
38 | ||
39 | if sys.version_info[0] >= 3: | |
40 | xml = dom.toxml(encoding=None) | |
41 | else: | |
42 | xml = dom.toxml() | |
43 | ||
37 | 44 | stdout.write(xml) |
38 | 45 | stdout.write('\n') |