.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
answerer Namespace Reference

Functions

 random_characters ()
 
 random_string ()
 
 random_float ()
 
 random_int ()
 
 random_sha256 ()
 
 random_uuid ()
 
 random_color ()
 
 answer (query)
 
 self_info ()
 

Variables

tuple keywords = ('random',)
 
int random_int_max = 2**31
 
 random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase
 
dict random_types
 

Function Documentation

◆ answer()

answerer.answer ( query)

Definition at line 60 of file answerer.py.

60def answer(query):
61 parts = query.query.split()
62 if len(parts) != 2:
63 return []
64
65 if parts[1] not in random_types:
66 return []
67
68 return [{'answer': random_types[parts[1]]()}]
69
70
71# required answerer function
72# returns information about the answerer

◆ random_characters()

answerer.random_characters ( )

Definition at line 17 of file answerer.py.

17def random_characters():
18 return [random.choice(random_string_letters) for _ in range(random.randint(8, 32))]
19
20

Referenced by random_sha256(), and random_string().

+ Here is the caller graph for this function:

◆ random_color()

answerer.random_color ( )

Definition at line 43 of file answerer.py.

43def random_color():
44 color = "%06x" % random.randint(0, 0xFFFFFF)
45 return f"#{color.upper()}"
46
47

◆ random_float()

answerer.random_float ( )

Definition at line 25 of file answerer.py.

25def random_float():
26 return str(random.random())
27
28

◆ random_int()

answerer.random_int ( )

Definition at line 29 of file answerer.py.

29def random_int():
30 return str(random.randint(-random_int_max, random_int_max))
31
32

◆ random_sha256()

answerer.random_sha256 ( )

Definition at line 33 of file answerer.py.

33def random_sha256():
34 m = hashlib.sha256()
35 m.update(''.join(random_characters()).encode())
36 return str(m.hexdigest())
37
38

References random_characters().

+ Here is the call graph for this function:

◆ random_string()

answerer.random_string ( )

Definition at line 21 of file answerer.py.

21def random_string():
22 return ''.join(random_characters())
23
24

References random_characters().

+ Here is the call graph for this function:

◆ random_uuid()

answerer.random_uuid ( )

Definition at line 39 of file answerer.py.

39def random_uuid():
40 return str(uuid.uuid4())
41
42

◆ self_info()

answerer.self_info ( )

Definition at line 73 of file answerer.py.

73def self_info():
74 return {
75 'name': gettext('Random value generator'),
76 'description': gettext('Generate different random values'),
77 'examples': ['random {}'.format(x) for x in random_types],
78 }

Variable Documentation

◆ keywords

tuple answerer.keywords = ('random',)

Definition at line 11 of file answerer.py.

◆ random_int_max

int answerer.random_int_max = 2**31

Definition at line 13 of file answerer.py.

◆ random_string_letters

answerer.random_string_letters = string.ascii_lowercase + string.digits + string.ascii_uppercase

Definition at line 14 of file answerer.py.

◆ random_types

dict answerer.random_types
Initial value:
1= {
2 'string': random_string,
3 'int': random_int,
4 'float': random_float,
5 'sha256': random_sha256,
6 'uuid': random_uuid,
7 'color': random_color,
8}

Definition at line 48 of file answerer.py.