[Web-SIG] Draft of server/gateway base class now available

Phillip J. Eby pje at telecommunity.com
Wed Oct 6 08:39:42 CEST 2004


I've just checked in a set of server/gateway base classes into the wsgiref 
library.  The main class, BaseHandler, implements the structural flow of a 
WSGI application invocation, with stub methods for creating the various 
streams, variables, and so on, including some optional extensions like 
'wsgi.file_wrapper'.  Server/gateway implementations can subclass 
BaseHandler to fill in these stubs with appropriate implementations for 
their particular architecture.

Two other classes, BaseCGIHandler and CGIHandler, are usable as-is (more or 
less) for CGI and CGI-like environments.  BaseCGIHandler instances can be 
passed the streams and environ mapping to use, while CGIHandler takes them 
direct from the 'sys' and 'os' modules, while using different defaults for 
e.g. wsgi.multiprocess and wsgi.run_once.

The main things missing at the moment from BaseHandler are:

  * sensible default error handling
  * automatic addition of missing headers (e.g. Content-Length)
  * Any HTTP/1.1 support whatsoever  :)
  * a more comprehensive test suite
   (there is a simple test suite now, but it doesn't cover all code paths)

The wsgiref package comes with a small set of automated tests; they can be 
run automatically via 'python setup.py -q test'.  It also includes utility 
routines like 'setup_testing_defaults()' to populate a basic 'environ' for 
testing purposes, HTTP header manipulation support, and various other 
useful things for server and application implementors.

I've tried to write the package to work with Python 2.1 (e.g. Jython), 
though I may have missed a few idioms; if you're working with an older 
version of Python and experience any difficulties, please let me know.

Most everything in the package has moderately verbose docstrings, so using 
pydoc or 'help()' in the interpreter should help you get going.  For a 
quick start, you can run a WSGI application under CGI with:

     from wsgiref.handlers import CGIHandler
     CGIHandler().run(application)

FYI, the ViewCVS for wsgiref is:

     http://cvs.eby-sarna.com/wsgiref/

And you can also get it via anonymous CVS; see

     http://peak.telecommunity.com/Meta/AnonymousCVSAccess.html

for instructions, replacing 'co PEAK' with 'co wsgiref'.



More information about the Web-SIG mailing list