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.
This commit is contained in:
José Matos 2017-03-27 11:35:29 +01:00
parent 1269860b45
commit bcf715f398
2 changed files with 18 additions and 9 deletions

View File

@ -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 = []

View File

@ -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