def unset_cookie(self, key, strict=True): """ Unset a cookie with the given name (remove it from the response). If there are multiple cookies (e.g., two cookies with the same name and different paths or domains), all such cookies will be deleted. """ existing = self.headers.getall('Set-Cookie') if not existing: if not strict: return raise KeyError("No cookies at all have been set") del self.headers['Set-Cookie'] found = False for header in existing: cookies = _ExtendedCookie() cookies.load(header) if key in cookies: found = True del cookies[key] self._add_cookie(cookies) else: # this branching is required because Cookie.Morsel.output() # strips quotes from expires= parameter, so better use # it as is, if it hasn't changed self._add_cookie(header) if strict and not found: raise KeyError( "No cookie has been set with the name %r" % key)
def str_cookies(self): """ Return a *plain* dictionary of cookies as found in the request. """ env = self.environ source = env.get('HTTP_COOKIE', '') if 'webob._parsed_cookies' in env: vars, var_source = env['webob._parsed_cookies'] if var_source == source: return vars vars = {} if source: cookies = _ExtendedCookie() cookies.load(source) for name in cookies: value = cookies[name].value if value is None: continue unquote_match = QUOTES_RE.match(value) if unquote_match is not None: value = unquote_match.group(1) vars[name] = value env['webob._parsed_cookies'] = (vars, source) return vars