[mod_python] Re: best practices; was "is mod_python borked?"

Jorey Bump list at joreybump.com
Sun Nov 5 10:31:19 EST 2006


Graham Dumpleton wrote:
> Yes, forgot that '.' can be used in URL in place of '/' which can make
> it even more interesting. I am guessing though that for this to work,
> you would need to have been using SetHandler rather than AddHandler,
> as imagine that using AddHandler would cause issues with Apache's
> own attempt to match extensions against files. I'll have to try playing
> with it some time to remind myself.

Yes, my example uses SetHandler. Things get even more interesting when 
we alter the example module a bit, name it index.py, and name the 
instance index:

page = """<html>
<head><title>What Am I?</title></head>
<body><h1>Hello! What am I?</h1></body>
</html>
"""

class Dummy:
     def __call__(self):
         return page
     def html(self):
         return page

index = Dummy()

This adds some interesting possibilities to the list of URLs:

  http://host/dir/index.py/index.html
  http://host/dir/index/index.html
  http://host/dir/index/
  http://host/dir/index.html
  http://host/dir/
  http://host/dir/... many other variations

Using this technique, you could probably replace a small site of static 
pages entirely with index.py without breaking existing URLs. This 
assumes access is always gained through one of the following URLs:

  http://host/
  http://host/index.html

Since SetHandler is used, you would need to adjust your configuration to 
support serving other resources like images, but it's doable. I think 
there is a small demand for this functionality, since the question of 
running an entire site via Publisher does pop up once in a while, as 
well as a desire to hide the technology driving the site.

So, back on topic, we can end up with ugly URLs like this:

  http://host/dir/index.py/index.html/
  http://host/dir/index.py/index/html/

that are the exact equivalent of these more friendly ones:

  http://host/dir/index.html/
  http://host/dir/

Now forcing slashes is no longer an issue of inserting them in the 
appropriate context, but of Publisher trying to determine the 
developer's intent. Since I don't believe that this is possible, and 
also find the default flexibility to be useful, maybe the best approach 
to provide such functionality to those who want it is to pass an option 
to Publisher, or even create a formal plugin system to strap on optional 
features.



More information about the Mod_python mailing list