Blame SOURCES/gconf-3.2.6-python3.patch

6e9cc4
From dbd4f1bc1992c2942538980e76a50c8b8a758d70 Mon Sep 17 00:00:00 2001
6e9cc4
From: Takao Fujiwara <tfujiwar@redhat.com>
6e9cc4
Date: Fri, 11 Dec 2015 18:29:49 +0900
6e9cc4
Subject: [PATCH] gsettings-schema-convert: Support python3
6e9cc4
6e9cc4
Modified by Marek Kasik (use io instead of codecs and
6e9cc4
explicit usage of /usr/bin/python3).
6e9cc4
6e9cc4
https://bugzilla.gnome.org/show_bug.cgi?id=759334
6e9cc4
---
6e9cc4
 gsettings/gsettings-schema-convert | 43 ++++++++++++++++++++------------------
6e9cc4
 1 file changed, 23 insertions(+), 20 deletions(-)
6e9cc4
6e9cc4
diff --git a/gsettings/gsettings-schema-convert b/gsettings/gsettings-schema-convert
6e9cc4
index 913cc83..6ccf8c5 100755
6e9cc4
--- a/gsettings/gsettings-schema-convert
6e9cc4
+++ b/gsettings/gsettings-schema-convert
6e9cc4
@@ -1,4 +1,4 @@
6e9cc4
-#!/usr/bin/env python
6e9cc4
+#!/usr/bin/env python3
6e9cc4
 # vim: set ts=4 sw=4 et: coding=UTF-8
6e9cc4
 #
6e9cc4
 # Copyright (c) 2010, Novell, Inc.
6e9cc4
@@ -25,6 +25,9 @@
6e9cc4
 # TODO: we don't support migrating a pair from a gconf schema. It has yet to be
6e9cc4
 #       seen in real-world usage, though.
6e9cc4
 
6e9cc4
+from __future__ import print_function
6e9cc4
+
6e9cc4
+import io
6e9cc4
 import os
6e9cc4
 import sys
6e9cc4
 
6e9cc4
@@ -398,7 +401,7 @@ class SimpleSchemaParser:
6e9cc4
 
6e9cc4
     def _word_to_token(self, word):
6e9cc4
         lower = word.lower()
6e9cc4
-        if lower and lower in self.allowed_tokens.keys():
6e9cc4
+        if lower and lower in list(self.allowed_tokens.keys()):
6e9cc4
             return lower
6e9cc4
         raise GSettingsSchemaConvertException('\'%s\' is not a valid token.' % lower)
6e9cc4
 
6e9cc4
@@ -594,7 +597,7 @@ class SimpleSchemaParser:
6e9cc4
             self.object_stack.append(new_object)
6e9cc4
 
6e9cc4
     def parse(self):
6e9cc4
-        f = open(self.file, 'r')
6e9cc4
+        f = io.open(self.file, 'r', encoding='utf-8')
6e9cc4
         lines = [ line[:-1] for line in f.readlines() ]
6e9cc4
         f.close()
6e9cc4
 
6e9cc4
@@ -603,7 +606,7 @@ class SimpleSchemaParser:
6e9cc4
             for line in lines:
6e9cc4
                 current_line_nb += 1
6e9cc4
                 self.parse_line(line)
6e9cc4
-        except GSettingsSchemaConvertException, e:
6e9cc4
+        except GSettingsSchemaConvertException as e:
6e9cc4
             raise GSettingsSchemaConvertException('%s:%s: %s' % (os.path.basename(self.file), current_line_nb, e))
6e9cc4
 
6e9cc4
         return self.root
6e9cc4
@@ -711,7 +714,7 @@ class XMLSchemaParser:
6e9cc4
             schema = self._parse_schema(schema_node)
6e9cc4
 
6e9cc4
             for (child_schema, child_name) in schema._children:
6e9cc4
-                if parent.has_key(child_schema):
6e9cc4
+                if child_schema in parent:
6e9cc4
                     raise GSettingsSchemaConvertException('Child \'%s\' is declared by two different schemas: \'%s\' and \'%s\'.' % (child_schema, parent[child_schema], schema.id))
6e9cc4
                 parent[child_schema] = schema
6e9cc4
 
6e9cc4
@@ -719,7 +722,7 @@ class XMLSchemaParser:
6e9cc4
 
6e9cc4
         # now let's move all schemas where they should leave
6e9cc4
         for schema in schemas:
6e9cc4
-            if parent.has_key(schema.id):
6e9cc4
+            if schema.id in parent:
6e9cc4
                 parent_schema = parent[schema.id]
6e9cc4
 
6e9cc4
                 # check that the paths of parent and child are supported by
6e9cc4
@@ -1054,31 +1057,31 @@ def main(args):
6e9cc4
     (options, args) = parser.parse_args()
6e9cc4
 
6e9cc4
     if len(args) < 1:
6e9cc4
-        print >> sys.stderr, 'Need a filename to work on.'
6e9cc4
+        print('Need a filename to work on.', file=sys.stderr)
6e9cc4
         return 1
6e9cc4
     elif len(args) > 1:
6e9cc4
-        print >> sys.stderr, 'Too many arguments.'
6e9cc4
+        print('Too many arguments.', file=sys.stderr)
6e9cc4
         return 1
6e9cc4
 
6e9cc4
     if options.simple and options.xml:
6e9cc4
-        print >> sys.stderr, 'Too many output formats requested.'
6e9cc4
+        print('Too many output formats requested.', file=sys.stderr)
6e9cc4
         return 1
6e9cc4
 
6e9cc4
     if not options.gconf and options.gettext_domain:
6e9cc4
-        print >> sys.stderr, 'Default gettext domain can only be specified when converting a gconf schema.'
6e9cc4
+        print('Default gettext domain can only be specified when converting a gconf schema.', file=sys.stderr)
6e9cc4
         return 1
6e9cc4
 
6e9cc4
     if not options.gconf and options.schema_id:
6e9cc4
-        print >> sys.stderr, 'Default schema ID can only be specified when converting a gconf schema.'
6e9cc4
+        print('Default schema ID can only be specified when converting a gconf schema.', file=sys.stderr)
6e9cc4
         return 1
6e9cc4
 
6e9cc4
     if not options.gconf and options.keep_underscores:
6e9cc4
-        print >> sys.stderr, 'The --keep-underscores option can only be specified when converting a gconf schema.'
6e9cc4
+        print('The --keep-underscores option can only be specified when converting a gconf schema.', file=sys.stderr)
6e9cc4
         return 1
6e9cc4
 
6e9cc4
     argfile = os.path.expanduser(args[0])
6e9cc4
     if not os.path.exists(argfile):
6e9cc4
-        print >> sys.stderr, '\'%s\' does not exist.' % argfile
6e9cc4
+        print('\'%s\' does not exist.' % argfile, file=sys.stderr)
6e9cc4
         return 1
6e9cc4
 
6e9cc4
     if options.output:
6e9cc4
@@ -1095,7 +1098,7 @@ def main(args):
6e9cc4
             try:
6e9cc4
                 parser = GConfSchemaParser(argfile, options.gettext_domain, options.schema_id, options.keep_underscores)
6e9cc4
                 schema_root = parser.parse()
6e9cc4
-            except SyntaxError, e:
6e9cc4
+            except SyntaxError as e:
6e9cc4
                 raise GSettingsSchemaConvertException('\'%s\' does not look like a valid gconf schema file: %s' % (argfile, e))
6e9cc4
         else:
6e9cc4
             # autodetect if file is XML or not
6e9cc4
@@ -1104,7 +1107,7 @@ def main(args):
6e9cc4
                 schema_root = parser.parse()
6e9cc4
                 if not options.simple and not options.xml:
6e9cc4
                     options.simple = True
6e9cc4
-            except SyntaxError, e:
6e9cc4
+            except SyntaxError as e:
6e9cc4
                 parser = SimpleSchemaParser(argfile)
6e9cc4
                 schema_root = parser.parse()
6e9cc4
                 if not options.simple and not options.xml:
6e9cc4
@@ -1113,10 +1116,10 @@ def main(args):
6e9cc4
         if options.xml:
6e9cc4
             node = schema_root.get_xml_node()
6e9cc4
             try:
6e9cc4
-                output = ET.tostring(node, pretty_print = True)
6e9cc4
+                output = ET.tostring(node, pretty_print = True).decode(encoding='utf-8')
6e9cc4
             except TypeError:
6e9cc4
                 # pretty_print only works with lxml
6e9cc4
-                output = ET.tostring(node)
6e9cc4
+                output = ET.tostring(node).decode(encoding='utf-8')
6e9cc4
         else:
6e9cc4
             output = schema_root.get_simple_string()
6e9cc4
 
6e9cc4
@@ -1124,17 +1127,17 @@ def main(args):
6e9cc4
             sys.stdout.write(output)
6e9cc4
         else:
6e9cc4
             try:
6e9cc4
-                fout = open(options.output, 'w')
6e9cc4
+                fout = io.open(options.output, 'w', encoding='utf-8')
6e9cc4
                 fout.write(output)
6e9cc4
                 fout.close()
6e9cc4
-            except GSettingsSchemaConvertException, e:
6e9cc4
+            except GSettingsSchemaConvertException as e:
6e9cc4
                 fout.close()
6e9cc4
                 if os.path.exists(options.output):
6e9cc4
                     os.unlink(options.output)
6e9cc4
                 raise e
6e9cc4
 
6e9cc4
-    except GSettingsSchemaConvertException, e:
6e9cc4
-        print >> sys.stderr, '%s' % e
6e9cc4
+    except GSettingsSchemaConvertException as e:
6e9cc4
+        print('%s' % e, file=sys.stderr)
6e9cc4
         return 1
6e9cc4
 
6e9cc4
     return 0
6e9cc4
-- 
6e9cc4
2.4.3
6e9cc4