Package pyjamas :: Module Cookies
[hide private]
[frames] | no frames]

Source Code for Module pyjamas.Cookies

 1  # This is the gtk-dependent Cookies module. 
 2  # For the pyjamas/javascript version, see platform/CookiesPyJS.py 
 3   
 4  from __pyjamas__ import JS, doc 
 5  import pyjd 
 6  if pyjd.is_desktop: 
 7      from Cookie import SimpleCookie 
 8      import urllib 
 9      import datetime 
10      from string import strip 
11   
12 -def getCookie(key):
13 return getCookie2(key)
14
15 -def getCookie2(cookie_name):
16 cookiestr = doc().cookie 17 c = SimpleCookie(str(cookiestr)) 18 cs = c.get(cookie_name, None) 19 print "getCookie2", cookiestr, "name", cookie_name, "val", cs 20 if cs: 21 return cs.value 22 return None
23 24 # expires can be int or Date
25 -def setCookie(name, value, expires, domain=None, path=None, secure=False):
26 cookiestr = doc().cookie 27 c = SimpleCookie(str(cookiestr)) 28 c[name] = value 29 m = c[name] 30 d = datetime.datetime.now() + datetime.timedelta(0, expires/1000) 31 d = d.strftime("%a, %d %b %Y %H:%M:%S GMT") 32 m['expires'] = '"%s"' % d 33 if domain: 34 m['domain'] = domain 35 if path: 36 m['path'] = path 37 if secure: 38 m['secure'] = '' 39 40 c = c.output(header='').strip() 41 print "set cookies", c 42 _doc = doc() 43 _doc.cookie = c 44 45 return
46
47 -def get_crumbs():
48 docCookie = doc().cookie 49 c = SimpleCookie(docCookie) 50 c = c.output(header='') 51 return map(strip, c.split('\n'))
52
53 -def loadCookies():
54 pass
55