Bladeren bron

Merge bf9e6737de34d6a9e0a737262d2a3e23d92ae430 into f82ead3e303d75ba63a370dc038311e172e1330d

Matej Cotman 6 jaren geleden
bovenliggende
commit
ed3c140837
Geen account gekoppeld aan de committers e-mail
1 gewijzigde bestanden met toevoegingen van 21 en 3 verwijderingen
  1. 21
    3
      searx/answerers/random/answerer.py

+ 21
- 3
searx/answerers/random/answerer.py Bestand weergeven

@@ -1,6 +1,8 @@
1
+import hashlib
1 2
 import random
2 3
 import string
3 4
 import sys
5
+import uuid
4 6
 from flask_babel import gettext
5 7
 
6 8
 # required answerer attribute
@@ -16,9 +18,13 @@ else:
16 18
     random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase
17 19
 
18 20
 
21
+def random_characters():
22
+    return [random.choice(random_string_letters)
23
+            for _ in range(random.randint(8, 32))]
24
+
25
+
19 26
 def random_string():
20
-    return u''.join(random.choice(random_string_letters)
21
-                    for _ in range(random.randint(8, 32)))
27
+    return u''.join(random_characters())
22 28
 
23 29
 
24 30
 def random_float():
@@ -29,9 +35,21 @@ def random_int():
29 35
     return unicode(random.randint(-random_int_max, random_int_max))
30 36
 
31 37
 
38
+def random_sha256():
39
+    m = hashlib.sha256()
40
+    m.update(b''.join(random_characters()))
41
+    return unicode(m.hexdigest())
42
+
43
+
44
+def random_uuid():
45
+    return unicode(uuid.uuid4())
46
+
47
+
32 48
 random_types = {b'string': random_string,
33 49
                 b'int': random_int,
34
-                b'float': random_float}
50
+                b'float': random_float,
51
+                b'sha256': random_sha256,
52
+                b'uuid': random_uuid}
35 53
 
36 54
 
37 55
 # required answerer function