From 33fd938016def4496876d89d0ccaa53f47705005 Mon Sep 17 00:00:00 2001 From: misnyo Date: Mon, 4 Sep 2017 20:05:04 +0200 Subject: [mod] int_or_zero refactored to searx_utils --- searx/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'searx/utils.py') diff --git a/searx/utils.py b/searx/utils.py index 3df571160..35b20ad83 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -290,6 +290,15 @@ def convert_str_to_int(number_str): return 0 +# convert a variable to integer or return 0 if it's not a number +def int_or_zero(num): + if isinstance(num, list): + if len(num) < 1: + return 0 + num = num[0] + return convert_str_to_int(num) + + def is_valid_lang(lang): is_abbr = (len(lang) == 2) if is_abbr: -- cgit v1.2.3 From e73cb14889d29082c3a585644d547e6798fdb6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Thu, 20 Jul 2017 15:44:02 +0200 Subject: fix hmac python3 compatibility --- searx/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'searx/utils.py') diff --git a/searx/utils.py b/searx/utils.py index 35b20ad83..8be7beb62 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -1,4 +1,6 @@ import csv +import hashlib +import hmac import os import re @@ -321,3 +323,10 @@ def load_module(filename, module_dir): module = load_source(modname, filepath) module.name = modname return module + + +def new_hmac(secret_key, url): + if sys.version_info[0] == 2: + return hmac.new(bytes(secret_key), url, hashlib.sha256).hexdigest() + else: + return hmac.new(bytes(secret_key, 'utf-8'), url, hashlib.sha256).hexdigest() -- cgit v1.2.3