Browse Source

Merge bf9e6737de34d6a9e0a737262d2a3e23d92ae430 into f82ead3e303d75ba63a370dc038311e172e1330d

Matej Cotman 6 years ago
parent
commit
ed3c140837
No account linked to committer's email
1 changed files with 21 additions and 3 deletions
  1. 21
    3
      searx/answerers/random/answerer.py

+ 21
- 3
searx/answerers/random/answerer.py View File

1
+import hashlib
1
 import random
2
 import random
2
 import string
3
 import string
3
 import sys
4
 import sys
5
+import uuid
4
 from flask_babel import gettext
6
 from flask_babel import gettext
5
 
7
 
6
 # required answerer attribute
8
 # required answerer attribute
16
     random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase
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
 def random_string():
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
 def random_float():
30
 def random_float():
29
     return unicode(random.randint(-random_int_max, random_int_max))
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
 random_types = {b'string': random_string,
48
 random_types = {b'string': random_string,
33
                 b'int': random_int,
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
 # required answerer function
55
 # required answerer function