def application(cls, f): """Decorate a function as responder that accepts the request as first argument. This works like the `responder` decorator but the function is passed the request object as first argument:: @Request.application def my_wsgi_app(request): return Response('Hello World!') """ return _patch_wrapper(f, lambda *a: f(cls(a[-2]))(*a[-2:]))
def responder(f): """Marks a function as responder. Decorate a function with it and it will automatically call the return value as WSGI application. Example:: @responder def application(environ, start_response): return Response('Hello World!') """ return _patch_wrapper(f, lambda *a: f(*a)(*a[-2:]))
def middleware(self, func): """Like `make_middleware` but for decorating functions. Example usage:: @manager.middleware def application(environ, start_response): ... The difference to `make_middleware` is that the function passed will have all the arguments copied from the inner application (name, docstring, module). """ return _patch_wrapper(func, self.make_middleware(func))
def application(cls, f): """Decorate a function as responder that accepts the request as first argument. This works like the `responder` decorator but the function is passed the request object as first argument:: @Request.application def my_wsgi_app(request): return Response('Hello World!') """ #: return a callable that wraps the -2nd argument with the request #: and calls the function with all the arguments up to that one and #: the request. The return value is then called with the latest #: two arguments. This makes it possible to use this decorator for #: both methods and standalone WSGI functions. return _patch_wrapper(f, lambda *a: f(*a[:-2]+(cls(a[-2]),))(*a[-2:]))
def middleware(self, func): return _patch_wrapper(func, self.make_middleware(func))
def responder(f): return _patch_wrapper(f, lambda *a: f(*a)(*a[-2:]))
def application(cls, f): return _patch_wrapper(f, lambda *a: f(*(a[:-2] + (cls(a[-2]),)))(*a[-2:]))