From f104553af465f37165123b2cc8286bffbc2b2d25 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Tue, 18 Mar 2014 19:22:28 +0100 Subject: [PATCH] [mod][fix] cookie expiration ++ pep8 compatibility --- searx/webapp.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/searx/webapp.py b/searx/webapp.py index 44865345a..2f6aa4abe 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -57,6 +57,8 @@ babel = Babel(app) favicons = ['wikipedia', 'youtube', 'vimeo', 'soundcloud', 'twitter', 'stackoverflow', 'github'] +cookie_max_age = 60 * 60 * 24 * 365 * 23 # 23 years + @babel.localeselector def get_locale(): @@ -159,8 +161,10 @@ def index(): # TODO, check if timezone is calculated right if 'publishedDate' in result: - if result['publishedDate'].replace(tzinfo=None) >= datetime.now() - timedelta(days=1): - timedifference = datetime.now() - result['publishedDate'].replace(tzinfo=None) + if result['publishedDate'].replace(tzinfo=None)\ + >= datetime.now() - timedelta(days=1): + timedifference = datetime.now() - result['publishedDate']\ + .replace(tzinfo=None) minutes = int((timedifference.seconds / 60) % 60) hours = int(timedifference.seconds / 60 / 60) if hours == 0: @@ -168,7 +172,8 @@ def index(): else: result['publishedDate'] = gettext(u'{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes) # noqa else: - result['pubdate'] = result['publishedDate'].strftime('%a, %d %b %Y %H:%M:%S %z') + result['pubdate'] = result['publishedDate']\ + .strftime('%a, %d %b %Y %H:%M:%S %z') result['publishedDate'] = format_date(result['publishedDate']) if search.request_data.get('format') == 'json': @@ -256,24 +261,21 @@ def preferences(): user_blocked_engines = request.cookies.get('blocked_engines', '').split(',') # noqa if sorted(blocked_engines) != sorted(user_blocked_engines): - # cookie max age: 4 weeks resp.set_cookie( 'blocked_engines', ','.join(blocked_engines), - max_age=60 * 60 * 24 * 7 * 4 + max_age=cookie_max_age ) if locale: - # cookie max age: 4 weeks resp.set_cookie( 'locale', locale, - max_age=60 * 60 * 24 * 7 * 4 + max_age=cookie_max_age ) if lang: - # cookie max age: 4 weeks resp.set_cookie( 'language', lang, - max_age=60 * 60 * 24 * 7 * 4 + max_age=cookie_max_age ) if selected_categories: