From 4a009c85bb3a6a0c251c873fcec14bec870b1f01 Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Sat, 8 Apr 2017 20:58:16 +0200 Subject: [PATCH] #9006 care to make prefs2prefs.py python 3 compatible --- lib/scripts/prefs2prefs.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/scripts/prefs2prefs.py b/lib/scripts/prefs2prefs.py index 132e21a52d..064de9c1c3 100644 --- a/lib/scripts/prefs2prefs.py +++ b/lib/scripts/prefs2prefs.py @@ -31,15 +31,17 @@ # These will be different for the bind and ui files and for the preferences # file. +from __future__ import print_function import os, re, string, sys from getopt import getopt +import io ########################################################### # Utility functions, borrowed from layout2layout.py def trim_bom(line): " Remove byte order mark." - if line[0:3] == "\357\273\277": + if line[0:3] == u"\357\273\277": return line[3:] else: return line @@ -119,11 +121,11 @@ def abort(msg): ########################################################### def usage(): - print "%s [-l] [-p] infile outfile" % sys.argv[0] - print "or: %s [-l] [-p] outfile" % sys.argv[0] - print " -l: convert LFUNs (bind and ui files)" - print " -p: convert preferences" - print "Note that exactly one of -l and -p is required." + print ("%s [-l] [-p] infile outfile" % sys.argv[0]) + print ("or: %s [-l] [-p] outfile" % sys.argv[0]) + print (" -l: convert LFUNs (bind and ui files)") + print (" -p: convert preferences") + print ("Note that exactly one of -l and -p is required.") def main(argv): @@ -139,8 +141,8 @@ def main(argv): source = sys.stdin output = sys.stdout elif len(args) == 2: - source = open(args[0], 'rb') - output = open(args[1], 'wb') + source = io.open(args[0], 'r', encoding='utf_8', errors='surrogateescape') + output = io.open(args[1], 'w', encoding='utf_8', newline='\n') opened_files = True else: usage()