Blame SOURCES/gconf-3.2.6-python3.patch

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