python script as wsgi, cgi, or standalone
EDIT: See below for original, I realized this could be done cleanly with a decorator . The decorator wrapplication takes the number of the port to use when called as a standalone server. The EMiddle class is unnecessary, it's just used as middleware to update the environ to show it came via wsgi. If there's a cleaner way, let me know. #!/usr/bin/python import os class EMiddle(object): def __init__(self, app): self.app = app def __call__(self, env, start_response): env['hello'] = 'wsgi' return self.app(env, start_response) def wrapplication(port): def wrapper(wsgi_app): if 'TERM' in os.environ: print "serving on port: %i" % port os.environ['hello'] = 'standalone' from wsgiref.simple_server import make_server make_server('', port, wsgi_app).serve_forever() elif 'CGI' in os.environ.get('GATEWAY_INTERFACE',...