Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 51 lines (39 sloc) 1.449 kb
507b678 @kamens Let gae_mini_profiler users disable w/ a little UI on/off setting in cas...
kamens authored
1 import Cookie
2 import logging
3 import os
4
5 def get_cookie_value(key):
6 cookies = None
7 try:
8 cookies = Cookie.BaseCookie(os.environ.get('HTTP_COOKIE',''))
9 except Cookie.CookieError, error:
10 logging.debug("Ignoring Cookie Error, skipping get cookie: '%s'" % error)
11
12 if not cookies:
13 return None
14
15 cookie = cookies.get(key)
16
17 if not cookie:
18 return None
19
20 return cookie.value
21
22 # Cookie handling from http://appengine-cookbook.appspot.com/recipe/a-simple-cookie-class/
23 def set_cookie_value(key, value='', max_age=None,
24 path='/', domain=None, secure=None, httponly=False,
25 version=None, comment=None):
26 cookies = Cookie.BaseCookie()
27 cookies[key] = value
28 for var_name, var_value in [
29 ('max-age', max_age),
30 ('path', path),
31 ('domain', domain),
32 ('secure', secure),
33 #('HttpOnly', httponly), Python 2.6 is required for httponly cookies
34 ('version', version),
35 ('comment', comment),
36 ]:
37 if var_value is not None and var_value is not False:
38 cookies[key][var_name] = str(var_value)
39 if max_age is not None:
40 cookies[key]['expires'] = max_age
41
42 cookies_header = cookies[key].output(header='').lstrip()
43
44 if httponly:
45 # We have to manually add this part of the header until GAE uses Python 2.6.
46 cookies_header += "; HttpOnly"
47
48 return cookies_header
49
50
Something went wrong with that request. Please try again.