[mod_python] An odd use of the publisher

Erik Stephens mod_python at 24ksoftware.com
Sun Mar 14 09:18:25 EST 2004

On Sat, 13 Mar 2004, Colin Fox wrote:

> Ron Alford wrote:
> | Colin Fox wrote:
> |
> |> To get around the return issue, I'm finishing off my handler with this:
> |>
> |> ~    raise apache.SERVER_RETURN, apache.OK
> |
> |
> | How does a straight 'return' with no arguments work? I thought I was
> | using that at one point.
> |
> |
> | -Ron
> It doesn't work - but even if it did, what I'd like to return is the
> success/failure code, not a string (which is what it's expecting).
> I also want to be able to do redirections.

Can't you use util.redirect?


> Raising an exception gives me the control I want, it's just that it
> feels wierd to be doing that as a normal exit, rather than a problem exit.

Yeah, it is very weird.  I'm surprised it's working for you.  Maybe
I'm missing something about your requirements or architecture.

> I'd just like to be sure that nothing odd is going to happen if I raise
> an exception. Or alternatively, how I could get processing similar to
> what I get if I write my own handler (where you create a handler()
> function and return a success code).

Can't you just assume that if no exceptions have been raised, then
everything was successful?  Exception handling seems to me to be more
powerful and flexible than return codes.

I think you may be over-complicating things a bit.  I'd recommend that
you continue using publisher and factor out how you want each request
to get handled into a method or class.  Here's just one way:

class Page:

    def __call__(self, req):
            return self.get_contents(req)
            pass # your exception handling code here

class IndexPage:

    def get_contents(self, req):
        # This would be where you could put
        # your current handler stuff

index = IndexPage
about_us = AboutPage

Hope it helps and that I didn't misunderstand you completely :)

Best regards,

More information about the Mod_python mailing list