mirror of
https://github.com/searxng/searxng.git
synced 2025-08-03 02:22:22 +02:00
Drop Python 2 (1/n): remove unicode string and url_utils
This commit is contained in:
parent
272158944b
commit
1022228d95
112 changed files with 388 additions and 535 deletions
|
@ -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)
|
||||
|
|
|
@ -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]}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue