Ejemplo n.º 1
0
 def error(self, exc):
     if not self._started:
         request = wsgi.WsgiRequest(self.environ)
         content_type = request.content_types.best_match(
             ('text/html', 'text/plain'))
         uri = self.environ['RAW_URI']
         msg = 'Could not find %s' % uri
         logger.info(msg=msg)
         if content_type == 'text/html':
             html = wsgi.HtmlDocument(title=msg)
             html.body.append('<h1>%s</h1>' % msg)
             data = html.render()
             resp = wsgi.WsgiResponse(504, data, content_type='text/html')
         elif content_type == 'text/plain':
             resp = wsgi.WsgiResponse(504, msg, content_type='text/html')
         else:
             resp = wsgi.WsgiResponse(504, '')
         self.start_response(resp.status, resp.get_headers())
         self._done = True
         self.queue.put_nowait(resp.content[0])
Ejemplo n.º 2
0
 def request(self, **kwargs):
     environ = wsgi.test_wsgi_environ(**kwargs)
     return wsgi.WsgiRequest(environ)