mirror of
https://github.com/searxng/searxng.git
synced 2024-11-23 11:21:00 +00:00
542f7d0d7b
In the past, some files were tested with the standard profile, others with a profile in which most of the messages were switched off ... some files were not checked at all. - ``PYLINT_SEARXNG_DISABLE_OPTION`` has been abolished - the distinction ``# lint: pylint`` is no longer necessary - the pylint tasks have been reduced from three to two 1. ./searx/engines -> lint engines with additional builtins 2. ./searx ./searxng_extra ./tests -> lint all other python files Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
78 lines
1.7 KiB
Python
78 lines
1.7 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import hashlib
|
|
import random
|
|
import string
|
|
import uuid
|
|
from flask_babel import gettext
|
|
|
|
# required answerer attribute
|
|
# specifies which search query keywords triggers this answerer
|
|
keywords = ('random',)
|
|
|
|
random_int_max = 2**31
|
|
random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase
|
|
|
|
|
|
def random_characters():
|
|
return [random.choice(random_string_letters) for _ in range(random.randint(8, 32))]
|
|
|
|
|
|
def random_string():
|
|
return ''.join(random_characters())
|
|
|
|
|
|
def random_float():
|
|
return str(random.random())
|
|
|
|
|
|
def random_int():
|
|
return str(random.randint(-random_int_max, random_int_max))
|
|
|
|
|
|
def random_sha256():
|
|
m = hashlib.sha256()
|
|
m.update(''.join(random_characters()).encode())
|
|
return str(m.hexdigest())
|
|
|
|
|
|
def random_uuid():
|
|
return str(uuid.uuid4())
|
|
|
|
|
|
def random_color():
|
|
color = "%06x" % random.randint(0, 0xFFFFFF)
|
|
return f"#{color.upper()}"
|
|
|
|
|
|
random_types = {
|
|
'string': random_string,
|
|
'int': random_int,
|
|
'float': random_float,
|
|
'sha256': random_sha256,
|
|
'uuid': random_uuid,
|
|
'color': random_color,
|
|
}
|
|
|
|
|
|
# required answerer function
|
|
# can return a list of results (any result type) for a given query
|
|
def answer(query):
|
|
parts = query.query.split()
|
|
if len(parts) != 2:
|
|
return []
|
|
|
|
if parts[1] not in random_types:
|
|
return []
|
|
|
|
return [{'answer': random_types[parts[1]]()}]
|
|
|
|
|
|
# required answerer function
|
|
# returns information about the answerer
|
|
def self_info():
|
|
return {
|
|
'name': gettext('Random value generator'),
|
|
'description': gettext('Generate different random values'),
|
|
'examples': ['random {}'.format(x) for x in random_types],
|
|
}
|