summaryrefslogtreecommitdiff
path: root/searx/utils.py
diff options
context:
space:
mode:
authorJohannes Schauer <josch@debian.org>2018-02-20 13:49:55 +0100
committerJohannes Schauer <josch@debian.org>2018-02-20 13:52:45 +0100
commitf6da658cf1d976fdd7847593ba96857e2c14fc8b (patch)
treea548673c4b66d77d8e9f9f12169ac3fc09c400fc /searx/utils.py
parent1619b7943f59fd6784ff70afdd604570f9bebc52 (diff)
New upstream version 0.14.0+dfsg1
Diffstat (limited to 'searx/utils.py')
-rw-r--r--searx/utils.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/searx/utils.py b/searx/utils.py
index 9494bdf..8f095f3 100644
--- a/searx/utils.py
+++ b/searx/utils.py
@@ -7,6 +7,7 @@ import re
from babel.dates import format_date
from codecs import getincrementalencoder
from imp import load_source
+from numbers import Number
from os.path import splitext, join
from random import choice
import sys
@@ -336,3 +337,14 @@ def new_hmac(secret_key, url):
return hmac.new(bytes(secret_key), url, hashlib.sha256).hexdigest()
else:
return hmac.new(bytes(secret_key, 'utf-8'), url, hashlib.sha256).hexdigest()
+
+
+def to_string(obj):
+ if isinstance(obj, basestring):
+ return obj
+ if isinstance(obj, Number):
+ return unicode(obj)
+ if hasattr(obj, '__str__'):
+ return obj.__str__()
+ if hasattr(obj, '__repr__'):
+ return obj.__repr__()