Mod_python’s Publisher Handler
Time and time again I find myself adoring the simplicity in which Python allows you to get things done, mod_python’s Publisher Handler is another fine example of this. It allows you to use REST style url (or any other style for that matters) to access functions in python modules. This is especially heartfelt after months of trudging through servlets.
Let’s give an example, say you have a function in mood.py as,
def happy(req, reason="no reason"): return "I'm happy for %s" % reason
Accessing http://host/mood.py/happy would return “I’m happy for no reason”. What’s even cooler is that you can access url parameters via the parameter of the function, so accessing http://host/happy?reason=”it’s sunny” would give “I’m happy for it’s sunny”. If happy is defined in index.py you could access it directly under the url of that directoy (e.g., http://host/happy). Authentication? no problem, define __auth__ as a function to validate, or as a dictionary to contain username passwords.
It’s not for everything but it’s hard to beat for a quickie.
One Response to “Mod_python’s Publisher Handler”
Leave a Reply
You must be logged in to post a comment.
December 6th, 2005 at 2:56 pm
[...] The script, writing in mod python, uses feedparser to grab an image location. It then fetches it and returns the image content. [...]