on master help sign in
[fix] read utf-8 files (settings, languages, currency) with python3.5

Related to discussion in #1124 The io.open import is necessary for python2

commit829032f306cec8f6d109bfb037a01dc50ff87442 authorMarc Abonce Seguin <marc-abonce@mailbox.org> dateTue 16 Jan 2018, 23:05 (9 years ago) parent5947c05
3 files changed+6−3
searx/__init__.py+2−1 searx/engines/__init__.py+2−1 searx/engines/currency_convert.py+2−1
searx/__init__.py+2−1
@@ -19,6 +19,7 @@ import certifi
1919import logging
2020from os import environ
2121from os.path import realpath, dirname, join, abspath, isfile
22+from io import open
2223from ssl import OPENSSL_VERSION_INFO, OPENSSL_VERSION
2324try:
2425 from yaml import load
@@ -50,7 +51,7 @@ if not settings_path:
5051 raise Exception('settings.yml not found')
5152
5253# load settings
53−with open(settings_path, 'rb') as settings_yaml:
54+with open(settings_path, 'r', encoding='utf-8') as settings_yaml:
5455 settings = load(settings_yaml)
5556
5657'''
searx/engines/__init__.py+2−1
@@ -19,6 +19,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
1919import sys
2020import threading
2121from os.path import realpath, dirname
22+from io import open
2223from flask_babel import gettext
2324from operator import itemgetter
2425from json import loads
@@ -36,7 +37,7 @@ engines = {}
3637
3738categories = {'general': []}
3839
39−languages = loads(open(engine_dir + '/../data/engines_languages.json', 'rb').read())
40+languages = loads(open(engine_dir + '/../data/engines_languages.json', 'r', encoding='utf-8').read())
4041
4142engine_shortcuts = {}
4243engine_default_args = {'paging': False,
searx/engines/currency_convert.py+2−1
@@ -4,6 +4,7 @@ import os
44import sys
55import unicodedata
66
7+from io import open
78from datetime import datetime
89
910if sys.version_info[0] == 3:
@@ -94,7 +95,7 @@ def load():
9495 global db
9596
9697 current_dir = os.path.dirname(os.path.realpath(__file__))
97− json_data = open(current_dir + "/../data/currencies.json", 'rb').read()
98+ json_data = open(current_dir + "/../data/currencies.json", 'r', encoding='utf-8').read()
9899
99100 db = json.loads(json_data)
100101