Browse Source

[mod][fix] cookie expiration ++ pep8 compatibility

Adam Tauber 11 years ago
parent
commit
f104553af4
1 changed files with 11 additions and 9 deletions
  1. 11
    9
      searx/webapp.py

+ 11
- 9
searx/webapp.py View File

57
 favicons = ['wikipedia', 'youtube', 'vimeo', 'soundcloud',
57
 favicons = ['wikipedia', 'youtube', 'vimeo', 'soundcloud',
58
             'twitter', 'stackoverflow', 'github']
58
             'twitter', 'stackoverflow', 'github']
59
 
59
 
60
+cookie_max_age = 60 * 60 * 24 * 365 * 23  # 23 years
61
+
60
 
62
 
61
 @babel.localeselector
63
 @babel.localeselector
62
 def get_locale():
64
 def get_locale():
159
 
161
 
160
         # TODO, check if timezone is calculated right
162
         # TODO, check if timezone is calculated right
161
         if 'publishedDate' in result:
163
         if 'publishedDate' in result:
162
-            if result['publishedDate'].replace(tzinfo=None) >= datetime.now() - timedelta(days=1):
163
-                timedifference = datetime.now() - result['publishedDate'].replace(tzinfo=None)
164
+            if result['publishedDate'].replace(tzinfo=None)\
165
+               >= datetime.now() - timedelta(days=1):
166
+                timedifference = datetime.now() - result['publishedDate']\
167
+                    .replace(tzinfo=None)
164
                 minutes = int((timedifference.seconds / 60) % 60)
168
                 minutes = int((timedifference.seconds / 60) % 60)
165
                 hours = int(timedifference.seconds / 60 / 60)
169
                 hours = int(timedifference.seconds / 60 / 60)
166
                 if hours == 0:
170
                 if hours == 0:
168
                 else:
172
                 else:
169
                     result['publishedDate'] = gettext(u'{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes)  # noqa
173
                     result['publishedDate'] = gettext(u'{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes)  # noqa
170
             else:
174
             else:
171
-                result['pubdate'] = result['publishedDate'].strftime('%a, %d %b %Y %H:%M:%S %z')
175
+                result['pubdate'] = result['publishedDate']\
176
+                    .strftime('%a, %d %b %Y %H:%M:%S %z')
172
                 result['publishedDate'] = format_date(result['publishedDate'])
177
                 result['publishedDate'] = format_date(result['publishedDate'])
173
 
178
 
174
     if search.request_data.get('format') == 'json':
179
     if search.request_data.get('format') == 'json':
256
         user_blocked_engines = request.cookies.get('blocked_engines', '').split(',')  # noqa
261
         user_blocked_engines = request.cookies.get('blocked_engines', '').split(',')  # noqa
257
 
262
 
258
         if sorted(blocked_engines) != sorted(user_blocked_engines):
263
         if sorted(blocked_engines) != sorted(user_blocked_engines):
259
-            # cookie max age: 4 weeks
260
             resp.set_cookie(
264
             resp.set_cookie(
261
                 'blocked_engines', ','.join(blocked_engines),
265
                 'blocked_engines', ','.join(blocked_engines),
262
-                max_age=60 * 60 * 24 * 7 * 4
266
+                max_age=cookie_max_age
263
             )
267
             )
264
 
268
 
265
         if locale:
269
         if locale:
266
-            # cookie max age: 4 weeks
267
             resp.set_cookie(
270
             resp.set_cookie(
268
                 'locale', locale,
271
                 'locale', locale,
269
-                max_age=60 * 60 * 24 * 7 * 4
272
+                max_age=cookie_max_age
270
             )
273
             )
271
 
274
 
272
         if lang:
275
         if lang:
273
-            # cookie max age: 4 weeks
274
             resp.set_cookie(
276
             resp.set_cookie(
275
                 'language', lang,
277
                 'language', lang,
276
-                max_age=60 * 60 * 24 * 7 * 4
278
+                max_age=cookie_max_age
277
             )
279
             )
278
 
280
 
279
         if selected_categories:
281
         if selected_categories: