[Web-SIG] Sample WSGI server
Phillip J. Eby
pje at telecommunity.com
Tue Jan 27 11:21:35 EST 2004
FYI, you can find a sample WSGI gateway based on BaseHTTPServer at:
http://cvs.eby-sarna.com/PEAK/src/peak/util/WSGIServer.py?rev=HEAD&content-type=text/vnd.viewcvs-markup
Although it's in the 'peak.util' package, it can be used as a standalone
module without installing or using any portion of PEAK whatsoever.
This example should give a rough idea of the complexity of implementing
WSGI in a web server that does not have CGI or a CGI-like internal
interface already in existence.
Implementing a gateway over an existing CGI or CGI-like protocol (e.g.
FastCGI, SCGI, etc.) is much simpler as it requires only ensuring that the
file-like objects support the right methods and that
'isinstance(environ,dict)', and that 'environ' may be safely modified by
the called service.
In the most trivial case, this short snippet:
#!python
from someservice import myservice
import sys,os
aService = myservice(someparam="something")
aService.runCGI(sys.stdin,sys.stdout,sys.stderr,os.environ.copy())
is sufficient to run a WSGI service under CGI.
More information about the Web-SIG
mailing list