summarylogtreecommitdiffstats
path: root/medit-python3.diff
blob: fa03250496d687ec9e56c23b8cb7434ea93b8f8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
--- a/tools/glade2c.py	2012-12-16 23:55:32.000000000 +0000
+++ b/tools/glade2c.py
@@ -5,7 +5,7 @@ import sys
 import getopt
 import xml.dom
 import xml.dom.minidom as minidom
-import StringIO
+import io
 
 def name_is_nice(name):
     return name[-1:] not in "0123456789"
@@ -50,7 +50,7 @@ class GladeXml(object):
         walk_node(root, False, check_node)
 
     def format_buffer(self):
-        out = StringIO.StringIO()
+        out = io.StringIO()
         for l in self.buffer.splitlines():
             out.write('"')
             out.write(l.replace('\\', '\\\\').replace('"', '\\"'))
@@ -208,9 +208,9 @@ G_GNUC_UNUSED static %(XmlStruct)s *
 }
 """
 
-    buf = StringIO.StringIO()
+    buf = io.StringIO()
     if gxml.widgets:
-        print >> buf, ''
+        print('', file=buf)
         for w in gxml.widgets:
             name = w.name
             ct = params.id_map.get(name)
@@ -218,11 +218,11 @@ G_GNUC_UNUSED static %(XmlStruct)s *
                 class_name = w.class_name
             else:
                 class_name = ct[0]
-            print >> buf, '    %s *%s;' % (class_name, name)
+            print('    %s *%s;' % (class_name, name), file=buf)
     glade_xml_widgets_decl = buf.getvalue()
     buf.close()
 
-    buf = StringIO.StringIO()
+    buf = io.StringIO()
     for w in gxml.widgets:
         name = w.name
         ct = params.id_map.get(name)
@@ -230,20 +230,20 @@ G_GNUC_UNUSED static %(XmlStruct)s *
             class_name = w.class_name
         else:
             class_name = ct[0]
-        print >> buf, """\
+        print("""\
     xml->%(struct_mem)s = (%(class_name)s*) moo_glade_xml_get_widget (xml->xml, "%(glade_name)s");
-    g_return_val_if_fail (xml->%(struct_mem)s != NULL, FALSE);""" % { 'struct_mem': w.name, 'glade_name': w.real_name, 'class_name': class_name }
+    g_return_val_if_fail (xml->%(struct_mem)s != NULL, FALSE);""" % { 'struct_mem': w.name, 'glade_name': w.real_name, 'class_name': class_name }, file=buf)
     glade_xml_widgets_defs = buf.getvalue()
     buf.close()
 
-    buf = StringIO.StringIO()
+    buf = io.StringIO()
     for id in params.id_map:
         ct = params.id_map.get(id)
         if ct[1]:
             type_name = ct[1]
         else:
             type_name = 'g_type_from_name ("%s")' % (ct[0],)
-        print >> buf, '    moo_glade_xml_map_id (xml->xml, "%s", %s);' % (id, type_name)
+        print('    moo_glade_xml_map_id (xml->xml, "%s", %s);' % (id, type_name), file=buf)
     glade_xml_widgets_map = buf.getvalue()
     buf.close()
 
@@ -300,7 +300,7 @@ def convert_buffer(buf, params, output, 
 
         if output is None:
             output = sys.stdout
-        elif isinstance(output, str) or isinstance(output, unicode):
+        elif isinstance(output, str):
             output = open(output, 'w')
             close_output = True
 
@@ -317,7 +317,7 @@ def convert_file(filename, params, outpu
     return ret
 
 def usage():
-    print "Usage: %s [--map=id,ClassName,CLASS_TYPE...] [--output=outfile] FILE" % (sys.argv[0],)
+    print("Usage: %s [--map=id,ClassName,CLASS_TYPE...] [--output=outfile] FILE" % (sys.argv[0],))
 
 def main(args):
     params = ConvertParams()
@@ -325,8 +325,8 @@ def main(args):
     try:
         opts, files = getopt.getopt(args[1:], "hm:o:s:S:r:",
                                     ["help", "map=", "output=", "struct-name=", "StructName=", "root="])
-    except getopt.GetoptError, err:
-        print str(err)
+    except getopt.GetoptError as err:
+        print(str(err))
         usage()
         return 2
 
--- a/tools/xml2h.py	2012-12-16 23:55:32.000000000 +0000
+++ b/tools/xml2h.py
@@ -11,13 +11,13 @@ tmp_output = output + '.tmp'
 varname = sys.argv[3]
 
 outfile = open(tmp_output, 'w')
-print >> outfile, '/* -*- C -*- */'
-print >> outfile, 'static const char %s [] = ""' % (varname,)
+print('/* -*- C -*- */', file=outfile)
+print('static const char %s [] = ""' % (varname,), file=outfile)
 for line in open(input):
     if line.endswith('\n'):
         line = line[:-1]
-    print >> outfile, '"' + line.replace('"', '\\"') + '\\n"'
-print >> outfile, ';'
+    print('"' + line.replace('"', '\\"') + '\\n"', file=outfile)
+print(';', file=outfile)
 
 outfile.close()