Browse Source

[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 years ago
parent
commit
829032f306
3 changed files with 6 additions and 3 deletions
  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 View File

19
 import logging
19
 import logging
20
 from os import environ
20
 from os import environ
21
 from os.path import realpath, dirname, join, abspath, isfile
21
 from os.path import realpath, dirname, join, abspath, isfile
22
+from io import open
22
 from ssl import OPENSSL_VERSION_INFO, OPENSSL_VERSION
23
 from ssl import OPENSSL_VERSION_INFO, OPENSSL_VERSION
23
 try:
24
 try:
24
     from yaml import load
25
     from yaml import load
50
     raise Exception('settings.yml not found')
51
     raise Exception('settings.yml not found')
51
 
52
 
52
 # load settings
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
     settings = load(settings_yaml)
55
     settings = load(settings_yaml)
55
 
56
 
56
 '''
57
 '''

+ 2
- 1
searx/engines/__init__.py View File

19
 import sys
19
 import sys
20
 import threading
20
 import threading
21
 from os.path import realpath, dirname
21
 from os.path import realpath, dirname
22
+from io import open
22
 from flask_babel import gettext
23
 from flask_babel import gettext
23
 from operator import itemgetter
24
 from operator import itemgetter
24
 from json import loads
25
 from json import loads
36
 
37
 
37
 categories = {'general': []}
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
 engine_shortcuts = {}
42
 engine_shortcuts = {}
42
 engine_default_args = {'paging': False,
43
 engine_default_args = {'paging': False,

+ 2
- 1
searx/engines/currency_convert.py View File

4
 import sys
4
 import sys
5
 import unicodedata
5
 import unicodedata
6
 
6
 
7
+from io import open
7
 from datetime import datetime
8
 from datetime import datetime
8
 
9
 
9
 if sys.version_info[0] == 3:
10
 if sys.version_info[0] == 3:
94
     global db
95
     global db
95
 
96
 
96
     current_dir = os.path.dirname(os.path.realpath(__file__))
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
     db = json.loads(json_data)
100
     db = json.loads(json_data)
100
 
101