commit bcf715f398ead2e2c43af65bedcfecad27e48880
Author: José Matos <jama...@lyx.org>
Date:   Mon Mar 27 11:35:29 2017 +0100

    lyx2lyx: fix #9006 (python3 with non-utf8 encoding as the system default)
    
    This patch fixes lyx2lyx running on python 3 for those systems
    where the default encoding is not UTF-8, since open by default
    uses the default system encoding.
---
 lib/lyx2lyx/lyx_1_6.py         |   20 ++++++++++++--------
 lib/lyx2lyx/unicode_symbols.py |    7 ++++++-
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py
index b5650e2..636d4b2 100644
--- a/lib/lyx2lyx/lyx_1_6.py
+++ b/lib/lyx2lyx/lyx_1_6.py
@@ -23,12 +23,7 @@ import unicodedata
 import sys, os
 
 from parser_tools import find_token, find_end_of, find_tokens, get_value
-
-# Provide support for both python 2 and 3
-PY2 = sys.version_info[0] == 2
-if not PY2:
-    unichr = chr
-# End of code to support for both python 2 and 3
+from unicode_symbols import read_unicodesymbols
 
 ####################################################################
 # Private helper functions
@@ -151,9 +146,18 @@ def set_option(document, m, option, value):
     return l
 
 
-# FIXME: Use the version in unicode_symbols.py which has some bug fixes
-def read_unicodesymbols():
+# FIXME: Remove this function if the version imported from unicode_symbols 
works.
+# This function was the predecessor from that function, that in the meanwhile 
got
+# new fixes.
+def read_unicodesymbols2():
     " Read the unicodesymbols list of unicode characters and corresponding 
commands."
+
+    # Provide support for both python 2 and 3
+    PY2 = sys.version_info[0] == 2
+    if not PY2:
+        unichr = chr
+    # End of code to support for both python 2 and 3
+
     pathname = os.path.abspath(os.path.dirname(sys.argv[0]))
     fp = open(os.path.join(pathname.strip('lyx2lyx'), 'unicodesymbols'))
     spec_chars = []
diff --git a/lib/lyx2lyx/unicode_symbols.py b/lib/lyx2lyx/unicode_symbols.py
index f24f3a9..d9eeff9 100644
--- a/lib/lyx2lyx/unicode_symbols.py
+++ b/lib/lyx2lyx/unicode_symbols.py
@@ -29,7 +29,12 @@ if not PY2:
 def read_unicodesymbols():
     " Read the unicodesymbols list of unicode characters and corresponding 
commands."
     pathname = os.path.abspath(os.path.dirname(sys.argv[0]))
-    fp = open(os.path.join(pathname.strip('lyx2lyx'), 'unicodesymbols'))
+    filename = os.path.join(pathname.strip('lyx2lyx'), 'unicodesymbols')
+
+    # For python 3+ we have to specify the encoding for those systems
+    # where the default is not UTF-8
+    fp = open(filename, encoding="utf8") if (not PY2) else open(filename)
+
     spec_chars = []
     # A backslash, followed by some non-word character, and then a character
     # in brackets. The idea is to check for constructs like: \"{u}, which is 
how

Reply via email to