3 __all__ = ["cookies", "get", "add"]
8 req.ohead.add("Set-Cookie", ck.codec[nm].OutputString())
10 class cookiedict(object):
11 def __init__(self, req):
13 self.bk = http.cookies.SimpleCookie(req.ihead.get("Cookie"))
14 except http.cookies.CookieError:
15 self.bk = http.cookies.SimpleCookie()
16 self.codec = http.cookies.SimpleCookie()
17 req.oncommit(addcookies)
19 def __getitem__(self, name):
20 return self.bk[name].value
22 def __contains__(self, name):
23 return name in self.bk
25 def get(self, name, default = None):
26 if name not in self.bk:
28 return self.bk[name].value
30 def add(self, name, value, path = None):
31 self.codec[name] = value
32 if path is not None: self.codec[name]["path"] = path
34 def __setitem__(self, name, value):
38 return req.item(cookiedict)
40 def get(req, name, default = None):
41 return cookies(req).get(name, default)
43 def add(req, name, value, path = None):
44 cookies(req).add(name, value, path)