diff options
author | Adam Tauber <asciimoo@gmail.com> | 2017-12-01 20:45:24 +0100 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2017-12-01 20:54:12 +0100 |
commit | 0969e50c5bc949d2c15eaed8e6a7def6b9da00fa (patch) | |
tree | 7f7a77190b67585956e6109a882c68a934030bab /searx/utils.py | |
parent | a065fcdcc95beaf7028b55c9bd82591add99a890 (diff) | |
download | searxng-0969e50c5bc949d2c15eaed8e6a7def6b9da00fa.tar.gz searxng-0969e50c5bc949d2c15eaed8e6a7def6b9da00fa.zip |
[fix] convert json engine result attributes to string - closes #1006
Diffstat (limited to 'searx/utils.py')
-rw-r--r-- | searx/utils.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/searx/utils.py b/searx/utils.py index 9494bdf3d..8f095f3b0 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__() |