24 node, before, after =
get_node(external_bangs_db, bang)
26 bang_definition =
None
30 if k.startswith(after):
31 bang_ac_list.append(before + k)
32 elif isinstance(node, dict):
33 bang_definition = node.get(LEAF_KEY)
34 bang_ac_list = [before + k
for k
in node.keys()
if k != LEAF_KEY]
35 elif isinstance(node, str):
36 bang_definition = node
39 return bang_definition, bang_ac_list
58 if external_bangs_db
is None:
59 external_bangs_db = EXTERNAL_BANGS
64 current = [*bang_ac_list]
66 while len(current) > 0:
67 bang_ac = current.pop(0)
71 if current_bang_definition:
73 new_autocomplete.append((bang_ac, order))
74 for new_bang
in current_bang_ac_list:
75 if new_bang
not in done
and new_bang
not in current:
76 current.append(new_bang)
78 new_autocomplete.sort(key=
lambda t: (-t[1], t[0]))
79 new_autocomplete = list(map(
lambda t: t[0], new_autocomplete))
81 return bang_definition, new_autocomplete
86 Redirects if the user supplied a correct bang search.
87 :param search_query: This is a search_query object which contains preferences and the submitted queries.
88 :return: None if the bang was invalid, else a string of the redirect url.
92 if external_bangs_db
is None:
93 external_bangs_db = EXTERNAL_BANGS
95 if search_query.external_bang:
97 if bang_definition
and isinstance(bang_definition, str):