Since no such beast seemed to exist yet, I have hacked up a wrapper to turn an existing python CGI script into a WSGI application. The result is available from the
sysfs download area as cgi2wsgi.py.
The wrapper requires you to rename the original CGI script to somecgi.py (pick a name), make it available in the python path, and set the name you gave the script in the wrapper
wrapcgi method. This is due to the way it works: it mangles the environment and standard output, and then tries to import the CGI as a python module. Any output is gathered, split into headers and data and then returned to the WSGI server. An alternative approach could have been to create a full-fledged CGI environment and run the script by forking or another equivalent method, with the added bonus that this should work even to turn non-python CGI scripts into WSGI applications; but this looks like a lot more work than the import approach I used (which was tricky enough in certain details already).
The wrapper is not complete as it stands: there are a bunch of variables which are usually available to CGI scripts but aren't when the CGI is loaded by the wrapper. Also if your script uses globals and does not reset them to a sane state before use data may linger in between subsequent invocations. However, I have successfully run a few applications through it so it should provide a reasonably good base to start from. And it did show a few bugs which were not triggered in a standard CGI environment.
The best way to figure out weak spots in your CGI script is probably by running the wrapper in a WSGI server which is not run itself through CGI, to avoid the WSGI server environment leaking through to the application. If run standalone, the wrapper tries to use the
OwlFish.com WSGIUtils to this purpose.
Bugfixes, enhancements and feedback welcome at mechanix on rack66.net.
Comments
Mon, 18.08.2008 20:49 CEST
Congratulations!
Mon, 18.08.2008 09:07 CEST
oh my god, one very beautifull feeling.. I know on me :) The happiness! Ozgur
Thu, 03.07.2008 19:36 CEST
Everything's going great with the pregnancy. Only six weeks left now :) It's a hard tim e when you lose a baby, [...]
Tue, 01.07.2008 22:18 CEST
Robertsonian translocation how's thing turn out since las t Sept? I read your story abo ut the baby thing. I am [...]
Mon, 30.06.2008 14:36 CEST
I didn't know there were these kinds of exams. I am new to l inux and still don't know how to do barely anything in [...]
Sun, 06.04.2008 16:59 CEST
You're right, that not only so me, but many questions in the LPI are not up to date and tha t you probably don't use [...]
Fri, 04.04.2008 13:14 CEST
Sure, it does it's job fine (m ost of the time :). And it's straightforward. Why not us e it?
Thu, 27.03.2008 19:53 CET
You still use LILO?!
Thu, 27.03.2008 00:51 CET
Can't you use UUID-naming?
Tue, 18.03.2008 21:45 CET
If it were the old blog, it /m ight/ have been from some comm ent spam. Then again, I cou ldn't find any reference [...]