def test_delete_header(self): d = HeaderDict() d['Content-Type'] = 'test' d['Test'] = 'test' assert d.get('Content-Type') del d['Content-Type'] assert not d.get('Content-Type')
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 __init__(self, status_code=None, headers=None, body=None, version='1.1'): """ Args: status_code: an int representing the status code for the Response headers: A watson.http.headers.HeaderDict object containing valid response headers. body: The content for the response version: The Http version for the response """ super(Response, self).__init__(headers=headers, body=body) self.status_code = status_code self._headers = headers or HeaderDict() self.version = str(version)
def test_add_header(self): d = HeaderDict() d.add('CONTENT_TYPE', 'text/html') assert d.get('Content-Type') == 'text/html' assert d.get('CONTENT_TYPE') == 'text/html'
def test_tuple_pairs_multiple(self): d = HeaderDict({'Content-Type': 'text/html'}) d.add('Content-Type', 'text/xml') assert d() == [('Content-Type', 'text/html'), ('Content-Type', 'text/xml')]
def test_add_option(self): d = HeaderDict() d.add('CONTENT_TYPE', 'text/html', charset='utf-8') assert d.get('Content-Type') == 'text/html; charset=utf-8' assert d.get_option('Content-Type', 'charset') == 'utf-8' assert d.get_option('Content-Type', 'random', 'test') == 'test'
def test_tuple_pairs(self): d = HeaderDict({'Content-Type': 'text/html'}) assert d() == [('Content-Type', 'text/html')]
def headers(self, headers): if not isinstance(headers, HeaderDict): headers = HeaderDict(headers) self._headers = headers
def headers(self): if not self._headers: self._headers = HeaderDict() return self._headers