Example #1
0
 def _200(self, start_response, path):
     content = ''
     with open(path, 'rb') as handle:
         content = handle.read()
     header_list = []
     headers = Headers(header_list)
     headers['date'] = rfc1123_date()
     headers['content-type'] = mimetypes.guess_type(path)[0] or 'unknown'
     headers['content-length'] = str(len(content))
     status_str = '%d %s' % (httplib.OK, httplib.responses[httplib.OK])
     start_response(status_str, header_list)
     return content
Example #2
0
 def __call__(self, environ, start_response):
     try:
         return self.app(environ, start_response)
     except HttpError, e:
         header_list = []
         headers = Headers(header_list)
         response_msg = str(e)
         data = pformat(e.data)
         body = self.template.substitute(MESSAGE=response_msg, DATA=data)
         headers['content-length'] = str(len(body))
         headers['content-type'] = 'text/plain'
         headers['date'] = rfc1123_date()
         start_response(response_msg, header_list)
         return body
Example #3
0
 def __call__(self, environ, start_response):
     try:
         return self.app(environ, start_response)
     except:
         t, e, tb = sys.exc_info()
         header_list = []
         headers = Headers(header_list)
         status = httplib.INTERNAL_SERVER_ERROR
         error = httplib.responses[status]
         exception = format_exception_only(t, e)
         traceback = format_tb(tb)
         body = self.template.substitute(STATUS=str(status),
                                         ERROR=error,
                                         EXCEPTION=exception,
                                         TRACEBACK=traceback)
         headers['content-length'] = str(len(body))
         headers['content-type'] = 'text/plain'
         headers['date'] = rfc1123_date()
         response_msg = '%d %s' % (status, error)
         start_response(response_msg, header_list)
         return body
Example #4
0
 def __init__(self):
     self.status = None
     self.__header_list = []
     self.headers = Headers(self.__header_list)
     self.headers['date'] = rfc1123_date()
     self.cookies = SimpleCookie()