Bug #705028 - gen-western-table.py is not compatible with python3
authorArfrever Frehtes Taifersar Arahesis <Arfrever.FTA@GMail.Com>
Tue, 25 Feb 2014 15:04:47 +0000 (16:04 +0100)
committerMilan Crha <mcrha@redhat.com>
Tue, 25 Feb 2014 15:04:47 +0000 (16:04 +0100)
addressbook/libebook-contacts/gen-western-table.py

index cdd2514..3456fd8 100755 (executable)
 
 import sys
 
+if sys.version_info[0] >= 3:
+    stdin = sys.stdin.buffer
+    stdout = sys.stdout.buffer
+else:
+    stdin = sys.stdin
+    stdout = sys.stdout
+
 var = None
 strings = []
 
 def output():
-    print "static const gchar %s_table[] = {" % var
+    stdout.write(b"static const gchar " + var + b"_table[] = {\n")
     for s in strings:
-        print "  \"%s\\0\"" % s
-    print "};"
+        stdout.write(b"  \"" + s + b"\\0\"\n")
+    stdout.write(b"};\n")
 
-    print "static const guint %s_index[] = {" % var
+    stdout.write(b"static const guint " + var + b"_index[] = {\n")
     index = 0
     for s in strings:
-        print "  %d," % index
+        stdout.write(b"  " + str(index).encode() + b",\n")
         index += len(s) + 1
-    print "};\n"
+    stdout.write(b"};\n\n")
     
 (S_VAR, S_STRING) = range(0, 2)
 state = S_VAR
 
-print "/* This file is generated by gen-western-table.py. DO NOT EDIT */"
+stdout.write(b"/* This file is generated by gen-western-table.py. DO NOT EDIT */\n")
 
-for l in sys.stdin.readlines():
+for l in stdin.readlines():
     l = l.strip()
-    if l == "":
+    if l == b"":
         state = S_VAR
         output()
         var = None