on master help sign in
Merge pull request #1148 from MarcAbonce/python3.5-fix

[fix] Read utf-8 files (settings, languages, currency) with Python3.5

commit4ad5e6ad4f1e5ce89eb7d1135ada712fdd9ce6b6 authorAdam Tauber <asciimoo@gmail.com> dateWed 17 Jan 2018, 22:05 (9 years ago) parent8511e64829032f
4 files changed+7−3
.travis.yml+1 searx/__init__.py+2−1 searx/engines/__init__.py+2−1 searx/engines/currency_convert.py+2−1
.travis.yml+1
@@ -9,6 +9,7 @@ addons:
99language: python
1010python:
1111 - "2.7"
12+ - "3.5"
1213 - "3.6"
1314before_install:
1415 - "export DISPLAY=:99.0"
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