> One last thing. Running under Medusa, a way to send out static files is > needed. Two implementations are present in the mailing list archive, at > these URLs: > > http://mail.mems-exchange.org/pipermail/quixote-users/2002-September/000788.html > (courtesy of Hamish Lawson) > > http://mail.mems-exchange.org/pipermail/quixote-users/2002-September/000792.html > (courtesy of Jon Corbet, from whom we're all still awaiting some > fragment of the LWN code ;^) ) > > Any chance of something similar landing into the codebase? I take that back, there may be a better way. :^) I tried the Lawson implementation, with correction from the Corbet one, but could not get it to work well: for some reason, the files always come back truncated at the first kbyte. :^( Instead of trying to solve this problem, it dawned on me that Quixote always needs a web server in front of it, be it Apache, Medusa, Twisted or whatever else, so it makes sense to serve the static files directly through that, instead of through Quixote. Medusa is a bit underdocumented, but with a little study of the sources (medusa/demo/publish.py and quixote/server/medusa_http.py, mainly) I was able to understand the interaction among different handlers, and came up with another small patch (attached) to medusa_http.py. It lets Medusa directly serve the files contained in a chosen directory ("Static" in the patch, look at the "match" function), while letting everything else through to Quixote. One may do the opposite, of course. It is just an example, and not really ready for inclusion into Quixote, but is short enough to be easily understandable, or so I hope. Enjoy. :^) -- "We should forget about small efficiencies, about 97% of the time. Premature optimization is the root of all evil." Donald Knuth Nicola Larosa - nico@tekNico.net
--- medusa_http.py Mon Aug 5 18:41:57 2002 +++ medusa_http.py.new Wed Nov 6 13:32:16 2002 @@ -9,7 +9,7 @@ import asyncore, rfc822, socket from StringIO import StringIO -from medusa import http_server, xmlrpc_handler +from medusa import default_handler, filesys, http_server, xmlrpc_handler from quixote.http_request import HTTPRequest from quixote.publish import Publisher @@ -26,8 +26,10 @@ self.server = server def match (self, request): - # Always match, since this is the only handler there is. - return True + if request.uri.startswith("/Static"): + return False + else: + return True def handle_request (self, request): msg = rfc822.Message(StringIO('\n'.join(request.header))) @@ -100,8 +102,12 @@ print 'Now serving the Quixote demo on port 8080' server = http_server.http_server('', 8080) publisher = Publisher('quixote.demo') - dh = QuixoteHandler(publisher, 'Quixote/demo', server) + qh = QuixoteHandler(publisher, 'Quixote/demo', server) + fs = filesys.os_filesystem( + '/opt/python/lib/python2.2/site-packages/quixote/demo/') + dh = default_handler.default_handler(fs) server.install_handler(dh) + server.install_handler(qh) asyncore.loop() if __name__ == '__main__':