diff options
author | Dalf <alex@al-f.net> | 2020-08-06 17:42:46 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2020-09-10 10:39:04 +0200 |
commit | 1022228d950c2a809ed613df1a515d9a6cafda7c (patch) | |
tree | d792dddea1a5b278b018ed4e024cd13340d5c1b1 /searx/answerers | |
parent | 272158944bf13503e2597018fc60a00baddec660 (diff) | |
download | searxng-1022228d950c2a809ed613df1a515d9a6cafda7c.tar.gz searxng-1022228d950c2a809ed613df1a515d9a6cafda7c.zip |
Drop Python 2 (1/n): remove unicode string and url_utils
Diffstat (limited to 'searx/answerers')
-rw-r--r-- | searx/answerers/__init__.py | 8 | ||||
-rw-r--r-- | searx/answerers/random/answerer.py | 20 | ||||
-rw-r--r-- | searx/answerers/statistics/answerer.py | 5 |
3 files changed, 10 insertions, 23 deletions
diff --git a/searx/answerers/__init__.py b/searx/answerers/__init__.py index 444316f11..47cc33ed3 100644 --- a/searx/answerers/__init__.py +++ b/searx/answerers/__init__.py @@ -1,12 +1,8 @@ from os import listdir from os.path import realpath, dirname, join, isdir -from sys import version_info from searx.utils import load_module from collections import defaultdict -if version_info[0] == 3: - unicode = str - answerers_dir = dirname(realpath(__file__)) @@ -36,10 +32,10 @@ def ask(query): results = [] query_parts = list(filter(None, query.query.split())) - if query_parts[0].decode('utf-8') not in answerers_by_keywords: + if query_parts[0].decode() not in answerers_by_keywords: return results - for answerer in answerers_by_keywords[query_parts[0].decode('utf-8')]: + for answerer in answerers_by_keywords[query_parts[0].decode()]: result = answerer(query) if result: results.append(result) diff --git a/searx/answerers/random/answerer.py b/searx/answerers/random/answerer.py index 4aafa2cfd..aaf9e1cf6 100644 --- a/searx/answerers/random/answerer.py +++ b/searx/answerers/random/answerer.py @@ -1,7 +1,6 @@ import hashlib import random import string -import sys import uuid from flask_babel import gettext @@ -10,12 +9,7 @@ from flask_babel import gettext keywords = ('random',) random_int_max = 2**31 - -if sys.version_info[0] == 2: - random_string_letters = string.lowercase + string.digits + string.uppercase -else: - unicode = str - random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase +random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase def random_characters(): @@ -24,25 +18,25 @@ def random_characters(): def random_string(): - return u''.join(random_characters()) + return ''.join(random_characters()) def random_float(): - return unicode(random.random()) + return str(random.random()) def random_int(): - return unicode(random.randint(-random_int_max, random_int_max)) + return str(random.randint(-random_int_max, random_int_max)) def random_sha256(): m = hashlib.sha256() m.update(''.join(random_characters()).encode()) - return unicode(m.hexdigest()) + return str(m.hexdigest()) def random_uuid(): - return unicode(uuid.uuid4()) + return str(uuid.uuid4()) random_types = {b'string': random_string, @@ -70,4 +64,4 @@ def answer(query): def self_info(): return {'name': gettext('Random value generator'), 'description': gettext('Generate different random values'), - 'examples': [u'random {}'.format(x.decode('utf-8')) for x in random_types]} + 'examples': ['random {}'.format(x.decode()) for x in random_types]} diff --git a/searx/answerers/statistics/answerer.py b/searx/answerers/statistics/answerer.py index 73dd25cfd..cfd1b3e23 100644 --- a/searx/answerers/statistics/answerer.py +++ b/searx/answerers/statistics/answerer.py @@ -1,11 +1,8 @@ -from sys import version_info from functools import reduce from operator import mul from flask_babel import gettext -if version_info[0] == 3: - unicode = str keywords = ('min', 'max', @@ -44,7 +41,7 @@ def answer(query): if answer is None: return [] - return [{'answer': unicode(answer)}] + return [{'answer': str(answer)}] # required answerer function |