def split_headers_server_vars(environ): """Splits the environ into headers and server pairs. """ headers = HeaderDict() server = MultiDict() cookies = CookieDict() for key in environ: if is_header(key): headers.add(http_header(key), environ[key]) if key == 'HTTP_COOKIE': cookies = CookieDict(environ[key]) cookies.modified = False else: server[key] = environ[key] return headers, server, cookies
def test_expire(self): cd = CookieDict() cd.add('test', 'something') cd.add('blah', 'test') cd.expire() assert cd['test']['expires'] == -1 assert cd['blah']['expires'] == -1
def __init__(self, method, get=None, post=None, files=None, headers=None, server=None, cookies=None, body=''): """Creates a new instance of the Request object. Args: method: The Http request method get: A watson.datastructures.MultiDict containing GET variables post: A watson.datastructures.MultiDict containing POST variables files: A watson.datastructures.MultiDict containing FieldStorage objects headers: A watson.http.headers.HeaderDict containing valid Http headers server: A watson.datastructures.MultiDict containing server variables cookies: A watson.http.cookies.CookieDict containing watson.http.cookies.TastyMorsel objects body: The content of the request """ super(Request, self).__init__(body=body, headers=headers) self._method = str(method).upper() if self.method not in REQUEST_METHODS: raise TypeError('Not a valid Http Request method.') self._get = get or MultiDict() self._post = post or MultiDict() self._files = files or MultiDict() self._server = server or MultiDict() self._cookies = cookies or CookieDict() self.headers = headers or HeaderDict()
def __copy__(self): return Request(self.method, get=copy(self.get), post=copy(self.post), files=copy(self.files), headers=HeaderDict(copy(self.headers)), server=copy(self.server), cookies=CookieDict(copy(self.cookies)), body=copy(self.body))
def test_add(self): cd = CookieDict() cd.add(name='test', value='something', expires=60, path='/home', domain='test.com', secure=True, httponly=True, comment='Blah') cookie = cd['test'] assert cookie.value == 'something' assert cookie['expires'] == 60 assert cookie['path'] == '/home' assert cookie['domain'] == 'test.com' assert cookie['secure'] assert cookie['httponly']
def test_output(self): cd = CookieDict() cd.add('test', 'something') cd.add('blah', 'test') assert str(cd) == 'blah=test; Path=/\r\ntest=something; Path=/'
def test_delete(self): cd = CookieDict() cd.add('test', 'something') cd.delete('test') assert cd['test']['expires'] == -1
def cookies(self, cookies): """Sets the cookies associated with the Response. """ if not isinstance(cookies, CookieDict): cookies = CookieDict(cookies) self._cookies = cookies
def cookies(self): """Returns the cookies associated with the Response. """ if not self._cookies: self._cookies = CookieDict() return self._cookies