[Web-SIG] Fun with WSGI -- commenting middleware.
Titus Brown
titus at caltech.edu
Sun Jan 30 03:44:47 CET 2005
Hi all,
I sat down today to hack out a simple commenting system for HTML
articles, and ended up using WSGI to implement a pipe-style solution.
You can see the results at
http://www.idyll.org/~t/articles.cgi/
This CGI script serves HTML files from a directory hierarchy. Anyone
can attach a comment to any HTML file served by the script.
Briefly, the solution consists of two WSGI apps, one a client called
"wsgiServeFiles" and the other a middleware app called "wsgiComment".
The command
app = wsgiServeFiles(directory)
creates a client app that will serve files out of the given directory
according to fairly simple rules.
The command
new_app = wsgiComment(app)
creates a wrapped client app that will allow you to comment paths under
the given app.
So, to create the site above, all I did was use the WSGI CGI
implementation and run the following command:
run_with_cgi(wsgiComment(wsgiServeFiles('/u/t/articles/text')))
The source code is pretty simple. I wanted something that would run via
CGI and require nothing other than local filesystem access and a Python
installation (no databases, etc.)
The code's available at
http://www.idyll.org/~t/articles.cgi/source/
It's still pretty hacky, and comments are appreciated.
Note that the commenting system should work for any WSGI client, although I
haven't tried it for anything else yet.
cheers,
--titus
More information about the Web-SIG
mailing list