summaryrefslogtreecommitdiff
path: root/searx/utils.py
diff options
context:
space:
mode:
authorApply55gx <Apply55gx@users.noreply.github.com>2017-10-25 10:44:28 +0200
committerGitHub <noreply@github.com>2017-10-25 10:44:28 +0200
commitd800e3fcfa44bc0be7262092815b2d2020a9d9f3 (patch)
tree0bdc64b3e15592e2fdeeaa40f21cbcc8039b7949 /searx/utils.py
parent18a4e7035f72a3c31239ae0bd1ee67cc2ad354b8 (diff)
parentb34124fd8a6b020136ca9656acdb01afceabe96f (diff)
downloadsearxng-d800e3fcfa44bc0be7262092815b2d2020a9d9f3.tar.gz
searxng-d800e3fcfa44bc0be7262092815b2d2020a9d9f3.zip
Merge pull request #1 from asciimoo/master
-
Diffstat (limited to 'searx/utils.py')
-rw-r--r--searx/utils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/searx/utils.py b/searx/utils.py
index 3df571160..8be7beb62 100644
--- a/searx/utils.py
+++ b/searx/utils.py
@@ -1,4 +1,6 @@
import csv
+import hashlib
+import hmac
import os
import re
@@ -290,6 +292,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:
@@ -312,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()