|
From: Titus B. <ti...@ca...> - 2003-01-10 18:48:08
|
A looooong time ago:
On Tue, Feb 19, 2002 at 11:17:04AM -0800, Chuck Esterbrook wrote:
-> On Tuesday 19 February 2002 10:37 am, Titus Brown wrote:
-> > Incidentally, for the PyWX out-of-process adapter I wouldn't have to
-> > change a single piece of code, were CGIAdapter a bit more flexible
-> > about accepting in/out arguments (rather than assuming
-> > sys.stdin/sys.stdout). ?Would you mind if I went in and added this
-> > flexibility (i.e. does it seem like a bad thing to have)?
->
-> Sounds fine to me.
Well, I finally got around to it ;).
Attached is a context diff against the current CVS that allows creators
of CGIAdapter objects to override sys.stdin, sys.stdout, sys.stderr, and
os.environ. This is necessary for threaded servers, because the
'sys' namespace (like all module namespaces) is per-process rather than
per-thread; hence, 'sys.stdin' cannot easily be over-ridden to point to
a connection-specific input handle when there are multiple connections
per process.
If this is confusing to anyone, all you really need to know is that
the following two calls to the CGIAdapter constructor are equivalent:
CGIAdapter(webKitDir)
CGIAdapter(webKitDir, sys.stdin, sys.stdout, sys.stderr, os.environ)
so everything should work as before, for those who don't change their
code.
Let me know if you have any questions...
This patch is necessary for the following Webware handler to work
in PyWX under threaded mode:
---
import sys, os, PyWX_buffer, ns_setup
from UserDict import UserDict
from WebKit.CGIAdapter import CGIAdapter
WebKit_dir = '/u/t/software/Webware-0.7/WebKit'
WebKit_base_url = '/WebKit.cgi'
def handle(conn):
environ = UserDict() # necessary for .data member.
environ.update(os.environ)
ns_setup.create_cgi_environ(conn, environ)
if not environ['CONTENT_LENGTH']:
environ['CONTENT_LENGTH'] = 0
environ['SCRIPT_NAME'] = WebKit_base_url
environ['PATH_INFO'] = conn.request.url[len(environ['SCRIPT_NAME']):]
buff = PyWX_buffer.GetBuff()
p = CGIAdapter(WebKit_dir, buff, buff, sys.stderr, environ)
p.run()
---
I'll check in examples etc. to the PyWX code base.
cheers,
--titus
|