def process(self, environ): request = Request(environ) response = self.route(request) if response is None: content = ["Cannot %s %r\r\n\r\nAvailable:" % (request.method, environ.get("PATH_INFO")[1:])] for regex, resource in Resource.routes: for method in ("get", "post", "put", "delete"): func = getattr(resource, method, None) if func: content.append(" %-6s %-35s # %s" % (method, resource.url, func.__doc__)) return Http404("\r\n".join(content)) elif not isinstance(response, Response): return Response( serialize.dump(response, request.format), headers=[("Content-type", "text/plain")] # % format ) else: return response
def serialize(self, format): from squash.util.serialize import dump return dump(self.details(), format)