On 29 March 2012 21:02, Masklinn <maskl...@masklinn.net> wrote: > Moving here as suggested by Terry Reedy as this list may be more > interested than -ideas (note: some feedback already used to revise > the original proposal, and a very basic patch — with no tests — is > provided for the current CPython default branch) > > Currently, calling wsgiref.simple_server simply mounts the (bundled) > demo app. > > I think that's a bit of a lost opportunity: the community seems to have > mostly standardized on a wsgi script providing an application callable > in its global namespace (though details may differ, mod_wsgi does not > care for the script's name and mandates an `application` callable while
Apache/mod_wsgi only defaults to 'application', it is configurable. As for the rest of the proposal, I tried to push the same idea a few years back with intent that all WSGI servers would provide a similar mechanism to that you describe as a lowest common denominator, but I didn't get anywhere at the time. Although people now perhaps appreciate more that a single approach would be better, it has ballooned now into a much bigger goal with the discussions on a common deployment mechanism. For example, a WARP file (Python WAR file equivalent) being the latest idea. This was touched on again at Web Summit at PyCon this year. Graham > e.g. gunicorn wants a Python module and the callable name must be > configured), and it would be nice if simple_server could take such a > script and mount the application provided: > > * This would allow testing that the script has no error without having > to go through mounting it in e.g. mod_wsgi > * It would make trivial/test applications (e.g. dynamic responders to > local JS) simpler to bootstrap as there would be no need for the > half-dozen lines of wsgiref.simple_server bootstrapping and "hard" > dependency on wsgiref, > > import wsgiref.simple_server > > def application(environ, start_response): > 'code' > > if __name__ == '__main__': > httpd = make_server('', 8000, application) > httpd.serve_forever() > > could become: > > def application(environ, start_response): > 'code' > > Since wsgiref already supports `python -mwsgiref.simple_server`, the > changes would be pretty simple: > > * an optional positional argument of the form `script[:app]`, the script > is exec'd, the application (called "application" by default) is > extracted and then mounted in simple_server. If no script is specified, > just mount `demo_app` as before > * Add -H/--host -p/--port options to, respectively, the hostname and the > port to bind the server to. > * The current -msimple_server uses `handle_request` and only replies once, > to increase the usability of the CLI tool use `serve_forever` *when and > only when the mounted application is not demo_app*. It also avoids > opening a hardcoded example URL on launch. > > This way the current sanity test/"PHPInfo" demo app works as it did before, > but it becomes possible to very easily serve a WSGI script with almost no > overhead in the script itself. > > Attachment: patch performing the above-specified alterations, using > argparse for arguments parsing and generation of help. > > > _______________________________________________ > Web-SIG mailing list > Web-SIG@python.org > Web SIG: http://www.python.org/sigs/web-sig > Unsubscribe: > http://mail.python.org/mailman/options/web-sig/graham.dumpleton%40gmail.com > _______________________________________________ Web-SIG mailing list Web-SIG@python.org Web SIG: http://www.python.org/sigs/web-sig Unsubscribe: http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com