Nicolas Lehuen wrote ..
> Well, I thought that if the file was modified, we needed to open it
> anyway, but you're right, that's optimising for a minority case. We
> might as well use stat and open the file only if it has changed.
> 
> I've wrote an alternative publisher a few months ago that overloaded
> this behaviour in the module cache to use
> req.finfo[apache.FINFO_MTIME] as the file modification time, thus
> saving us a call to fstat or stat entirely. I've stopped using this
> publisher because I thought that using the standard publisher was a
> better way to see how we could improve it, but anyway, I could back
> port this trick. If I don't get burned down by the flak I'm currently
> getting on the Python 2.2 issue, that is ;).

I'd rather you not use:

  req.finfo[apache.FINFO_MTIME]

for the same reasons I got you not to use it last time.

This is because now that req.filename/req.path_info are both writable,
it is possible for someone in their own handler to modify these values,
thus overriding Apache's own decisions about what matched the URL
and then explicitly invoke mod_python.publisher to service it. Because
req.finfo is not updatable by a handler, it isn't possible for a handler
to override it to make it consistent with changes to req.filename.

Thus in code I have:

  from lamia import handlers

  from mod_python import publisher

  __all__ = [ 'MapLocationToPublisher' ]

  class MapLocationToPublisher:

      def __init__(self,**kwargs):
          self.__call__ = handlers.MapLocationToView(
              directory = kwargs.pop('directory'),
              resource_extension = kwargs.pop('resource_extension','.py'),
              script_extension = '.py',
              handler = publisher.handler,
          )

The MapLocationToView handler object is doing stuff similar to what
Apache does as far as mapping URLs to files, but is actually applying
it against a configurable directory which doesn't even have to be in
the document tree. Once it maps to file and recalculates req.filename
and req.path_info appropriately, it calls mod_python.publisher.handler()
explicitly.

Graham

Reply via email to