Source code for spresso.model.web.base

from http.cookies import SimpleCookie


[docs]class Request(object): """ Base class defining the interface of a request. """ @property def method(self): """ Returns the HTTP method of the request. """ raise NotImplementedError @property def path(self): """ Returns the current path portion of the current uri. Used by some grants to determine which action to take. """ raise NotImplementedError
[docs] def get_param(self, name, default=None): """ Retrieve a parameter from the query string of the request. """ raise NotImplementedError
[docs] def post_param(self, name, default=None): """ Retrieve a parameter from the body of the request. """ raise NotImplementedError
[docs] def header(self, name, default=None): """ Retrieve a header of the request. """ raise NotImplementedError
@property def cookies(self): """ Retrieve a list of cookies from the header of the request. """ raise NotImplementedError
[docs]class Response(object): """ Contains data returned to the requesting user agent. """ def __init__(self): self.status_code = 200 self._headers = {"Content-Type": "text/html; charset=utf-8"} self.data = "" @property def headers(self): """ Return the headers of the response. Returns: dict: The headers. """ return self._headers
[docs] def add_header(self, header, value): """ Add a header to the response. Args: header(str): The identifier. value(str): The value. """ self._headers[header] = str(value)