[mod_python] Pre and postprocess blocks (Publisher mode)?

Graham Dumpleton graham.dumpleton at gmail.com
Mon May 7 05:33:07 EDT 2007


> I simplify my question:.
> I want to use only two callback functions: the first named "pre" must
> called by apache *before* the calling of published procedure, and the
> second (named "post") must called by apache *after* the calling of
> published procedure.
>
> So the question is that: can I set these two callback functions in the
> PUBLISHER HANDLER to initialize and finalize the request handling?
> Like in pylons?
>
> In pylons the controllers have _before_ and _after_ methods, they are
> called before/after the calling of the action method.
> Example:
> .... XController:
>   def __before__(self):
>        OpenSession()
>        OpenDB()
>        CheckLogin()
>    def __after__(sefl):
>        SaveSession()
>
>    def  index(self):
>         return Response('INDEX!')
>
> How to I use same mechanism in modpy3.3.1?
>
> Like this pseudocode:
>
> <Directory ...>
>    AddHandler publisher prefunctionname Pre postfunctionname Post
> ...

If you are not prepared to do it the Apache way, the simplest thing
would be to define your own custom mod_python handler:

  PythonHandler myhandler

In that handler, then do something like:

  import mod_python.publisher

  def handler(req):

    before(req)
    try:
        return mod_python.publisher.handler(req)
    finally:
        after(req)

Graham


More information about the Mod_python mailing list