瀏覽代碼

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

Related to discussion in #1124
The io.open import is necessary for python2
Marc Abonce Seguin 6 年之前
父節點
當前提交
829032f306
共有 3 個文件被更改,包括 6 次插入3 次删除
  1. 2
    1
      searx/__init__.py
  2. 2
    1
      searx/engines/__init__.py
  3. 2
    1
      searx/engines/currency_convert.py

+ 2
- 1
searx/__init__.py 查看文件

@@ -19,6 +19,7 @@ import certifi
19 19
 import logging
20 20
 from os import environ
21 21
 from os.path import realpath, dirname, join, abspath, isfile
22
+from io import open
22 23
 from ssl import OPENSSL_VERSION_INFO, OPENSSL_VERSION
23 24
 try:
24 25
     from yaml import load
@@ -50,7 +51,7 @@ if not settings_path:
50 51
     raise Exception('settings.yml not found')
51 52
 
52 53
 # load settings
53
-with open(settings_path, 'rb') as settings_yaml:
54
+with open(settings_path, 'r', encoding='utf-8') as settings_yaml:
54 55
     settings = load(settings_yaml)
55 56
 
56 57
 '''

+ 2
- 1
searx/engines/__init__.py 查看文件

@@ -19,6 +19,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
19 19
 import sys
20 20
 import threading
21 21
 from os.path import realpath, dirname
22
+from io import open
22 23
 from flask_babel import gettext
23 24
 from operator import itemgetter
24 25
 from json import loads
@@ -36,7 +37,7 @@ engines = {}
36 37
 
37 38
 categories = {'general': []}
38 39
 
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())
40 41
 
41 42
 engine_shortcuts = {}
42 43
 engine_default_args = {'paging': False,

+ 2
- 1
searx/engines/currency_convert.py 查看文件

@@ -4,6 +4,7 @@ import os
4 4
 import sys
5 5
 import unicodedata
6 6
 
7
+from io import open
7 8
 from datetime import datetime
8 9
 
9 10
 if sys.version_info[0] == 3:
@@ -94,7 +95,7 @@ def load():
94 95
     global db
95 96
 
96 97
     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()
98 99
 
99 100
     db = json.loads(json_data)
100 101