def request(self, environ): try: path = environ.get('PATH_INFO') if not path or path == '/': return self.home(environ) else: path = path[1:] leaf = True if path.endswith('/'): leaf = False path = path[:-1] keys = tuple(path.split('/')) bits = [] route = None while keys: route = self.routes.get(keys) if route: break bits.insert(0, keys[-1]) keys = keys[:-1] if route is None: raise HttpException(status=404) return route(self, environ, bits) except HttpException as e: status = e.status if has_empty_content(status, environ['REQUEST_METHOD']): return wsgi.WsgiResponse(status, response_headers=e.headers) else: content = error_messages.get(status,'') title = responses.get(status) content = '<h1>%s - %s</h1>%s' % (status, title, content) return self.render(content, title=title, status=status, headers=e.headers)
def response(self): return responses.get(self.status_code)
def get_status(self): code = self.status_code if code: return '%d %s' % (code, responses.get(code, 'Unknown'))