on master help sign in
[enh] gettext in self ip plugin
13ea0a2Adam Tauber
searx/plugins/self_ip.py+6−2
@@ -1,9 +1,12 @@
1−
1+from flask.ext.babel import gettext
2name = "Self IP"
2name = "Self IP"
3−description = "Display your source IP address"
3+description = gettext('Display your source IP address if the query expression is "ip"')
4default_on = True
4default_on = True
5
5
6
6
7+# attach callback to the pre search hook
8+# request: flask request object
9+# ctx: the whole local context of the pre search hook
7def pre_search(request, ctx):
10def pre_search(request, ctx):
8 if ctx['search'].query == 'ip':
11 if ctx['search'].query == 'ip':
9 x_forwarded_for = request.headers.getlist("X-Forwarded-For")
12 x_forwarded_for = request.headers.getlist("X-Forwarded-For")
@@ -13,5 +16,6 @@ def pre_search(request, ctx):
13 ip = request.remote_addr
16 ip = request.remote_addr
14 ctx['search'].answers.clear()
17 ctx['search'].answers.clear()
15 ctx['search'].answers.add(ip)
18 ctx['search'].answers.add(ip)
19+ # return False prevents exeecution of the original block
16 return False
20 return False
17 return True
21 return True