diff options
author | Adam Tauber <asciimoo@gmail.com> | 2017-10-25 23:56:37 +0200 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2017-10-26 00:06:03 +0200 |
commit | 5f758b2d39becf251a9097264d7414ad9c471d62 (patch) | |
tree | 82de6d5afbb0c73669f007225893a05e60d00601 /searx/preferences.py | |
parent | b34124fd8a6b020136ca9656acdb01afceabe96f (diff) | |
download | searxng-5f758b2d39becf251a9097264d7414ad9c471d62.tar.gz searxng-5f758b2d39becf251a9097264d7414ad9c471d62.zip |
[mod] compress saved preferences in url
Diffstat (limited to 'searx/preferences.py')
-rw-r--r-- | searx/preferences.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/searx/preferences.py b/searx/preferences.py index 92fe3853c..d10f4ffc7 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -1,6 +1,13 @@ +from base64 import urlsafe_b64encode, urlsafe_b64decode +from zlib import compress, decompress +from sys import version + from searx import settings, autocomplete from searx.languages import language_codes as languages -from searx.url_utils import urlencode +from searx.url_utils import parse_qs, urlencode + +if version[0] == '3': + unicode = str COOKIE_MAX_AGE = 60 * 60 * 24 * 365 * 5 # 5 years @@ -279,7 +286,11 @@ class Preferences(object): settings_kv['disabled_plugins'] = ','.join(self.plugins.disabled) settings_kv['enabled_plugins'] = ','.join(self.plugins.enabled) - return urlencode(settings_kv) + return urlsafe_b64encode(compress(urlencode(settings_kv).encode('utf-8'))).decode('utf-8') + + def parse_encoded_data(self, input_data): + decoded_data = decompress(urlsafe_b64decode(input_data.encode('utf-8'))) + self.parse_dict({x: y[0] for x,y in parse_qs(unicode(decoded_data)).items()}) def parse_dict(self, input_data): for user_setting_name, user_setting in input_data.items(): |