def _update_cookies(self, response): cookies = Cookie() # Load any generated cookies. for cookie in response.headers.getall('Set-Cookie'): cookies.load(cookie) self.cookies.update({i.name.decode('ascii'): i.value.decode('ascii') for i in cookies.values()})
def get_cookie(self, name, default=None): # webtest currently doesn't expose the unescaped cookie values # so we're using webob to parse them for us # see https://github.com/Pylons/webtest/issues/171 cookie = Cookie(' '.join('%s=%s' % (c.name, c.value) for c in self.cookiejar if c.name == name)) return next( (m.value.decode('latin-1') for m in cookie.values()), default, )
def unset_cookie(self, key, strict=True): """ Unset a cookie with the given name (remove it from the response). """ existing = self.headers.getall('Set-Cookie') if not existing and not strict: return cookies = Cookie() for header in existing: cookies.load(header) if key in cookies: del cookies[key] del self.headers['Set-Cookie'] for m in list(cookies.values()): self.headerlist.append(('Set-Cookie', str(m))) elif strict: raise KeyError("No cookie has been set with the name %r" % key)
def unset_cookie(self, key, strict=True): """ Unset a cookie with the given name (remove it from the response). """ existing = self.headers.getall('Set-Cookie') if not existing and not strict: return cookies = Cookie() for header in existing: cookies.load(header) if key in cookies: del cookies[key] del self.headers['Set-Cookie'] for m in cookies.values(): self.headerlist.append(('Set-Cookie', str(m))) elif strict: raise KeyError("No cookie has been set with the name %r" % key)
def unset_cookie(self, name, strict=True): """ Unset a cookie with the given name (remove it from the response). """ existing = self.headers.getall('Set-Cookie') if not existing and not strict: return cookies = Cookie() for header in existing: cookies.load(header) if isinstance(name, text_type): name = name.encode('utf8') if name in cookies: del cookies[name] del self.headers['Set-Cookie'] for m in cookies.values(): self.headerlist.append(('Set-Cookie', m.serialize())) elif strict: raise KeyError("No cookie has been set with the name %r" % name)
def unset_cookie(self, key, strict=True): """ Unset a cookie with the given name (remove it from the response). """ existing = self.headers.getall("Set-Cookie") if not existing and not strict: return cookies = Cookie() for header in existing: cookies.load(header) if isinstance(key, text_type): key = key.encode("utf8") if key in cookies: del cookies[key] del self.headers["Set-Cookie"] for m in cookies.values(): self.headerlist.append(("Set-Cookie", m.serialize())) elif strict: raise KeyError("No cookie has been set with the name %r" % key)