@@ -13,7 +13,7 @@ You should have received a copy of the GNU Affero General Public License
13along with searx. If not, see < http://www.gnu.org/licenses/ >.
13along with searx. If not, see < http://www.gnu.org/licenses/ >.
15(C) 2015 by Adam Tauber, <asciimoo@gmail.com>
15(C) 2015 by Adam Tauber, <asciimoo@gmail.com>
16−(C) 2018 by Vaclav Zouzalik
16+(C) 2018, 2020 by Vaclav Zouzalik
19from flask_babel import gettext
19from flask_babel import gettext
@@ -24,7 +24,7 @@ name = "Hash plugin"
24description = gettext("Converts strings to different hash digests.")
24description = gettext("Converts strings to different hash digests.")
25default_on = True
25default_on = True
27−parser_re = re.compile(b'(md5|sha1|sha224|sha256|sha384|sha512) (.*)', re.I)
27+parser_re = re.compile('(md5|sha1|sha224|sha256|sha384|sha512) (.*)', re.I)
30def post_search(request, search):
30def post_search(request, search):
@@ -37,7 +37,6 @@ def post_search(request, search):
37 return True
37 return True
39 function, string = m.groups()
39 function, string = m.groups()
40− function = str(function.decode('UTF-8')) # convert to string for python3
41 if string.strip().__len__() == 0:
40 if string.strip().__len__() == 0:
42 # end if the string is empty
41 # end if the string is empty
43 return True
42 return True
@@ -46,10 +45,10 @@ def post_search(request, search):
46 f = hashlib.new(function.lower())
45 f = hashlib.new(function.lower())
48 # make digest from the given string
47 # make digest from the given string
49− f.update(string.strip())
48+ f.update(string.encode('utf-8').strip())
50− digest = f.hexdigest()
49+ answer = function + " " + gettext('hash digest') + ": " + f.hexdigest()
52 # print result
51 # print result
53 search.result_container.answers.clear()
52 search.result_container.answers.clear()
54− search.result_container.answers.add(function + " " + gettext('hash function') + ": " + digest)
53+ search.result_container.answers['hash'] = { 'answer': answer }
55 return True
54 return True