diff options
author | Angristan <11699655+Angristan@users.noreply.github.com> | 2018-08-19 13:30:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-19 13:30:41 +0200 |
commit | c2da901afab28cc13794511709f70a0c76edc659 (patch) | |
tree | 7ef93394bf5c2a3d854ecd6fe2d04d3a6f7e3b4c /searx/answerers/random/answerer.py | |
parent | b75f1b6cc39a94989a74d52eb0f1267c3e3c665e (diff) | |
parent | 3126660be5e85a18ee386f49104d3bbb158a6386 (diff) | |
download | searxng-c2da901afab28cc13794511709f70a0c76edc659.tar.gz searxng-c2da901afab28cc13794511709f70a0c76edc659.zip |
Merge branch 'master' into patch-2
Diffstat (limited to 'searx/answerers/random/answerer.py')
-rw-r--r-- | searx/answerers/random/answerer.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/searx/answerers/random/answerer.py b/searx/answerers/random/answerer.py index f2b8bf3e5..b6e8422ad 100644 --- a/searx/answerers/random/answerer.py +++ b/searx/answerers/random/answerer.py @@ -1,6 +1,8 @@ +import hashlib import random import string import sys +import uuid from flask_babel import gettext # required answerer attribute @@ -16,9 +18,13 @@ else: 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 u''.join(random.choice(random_string_letters) - for _ in range(random.randint(8, 32))) + return u''.join(random_characters()) def random_float(): @@ -29,9 +35,21 @@ def random_int(): return unicode(random.randint(-random_int_max, random_int_max)) +def random_sha256(): + m = hashlib.sha256() + m.update(b''.join(random_characters())) + return unicode(m.hexdigest()) + + +def random_uuid(): + return unicode(uuid.uuid4()) + + random_types = {b'string': random_string, b'int': random_int, - b'float': random_float} + b'float': random_float, + b'sha256': random_sha256, + b'uuid': random_uuid} # required answerer function |