On 5/3/07, Max Ischenko <[EMAIL PROTECTED]> wrote:
>
>
> On 5/3/07, Ben Bangert <[EMAIL PROTECTED]> wrote:
> > The WSGIController (that BaseController inherits from) will actually
> > run your __before__ methods, putting code in __call__ means you can
> > load even before that. Perhaps you have code that has to run before
> > some inherited controllers __before__ method, putting it in __call__
> > ensures that its called in advance.
>
> There is a caveat in using methods like __before__. The base class'
> implementation needs to be called explicitly (as with any super impl). Which
> means putting "common" logic into BaseController.__before__ poses the threat
> that subclass may failed to execute it.
>
> I am interested in hearing how others deal with this issue. I ended up
> having an empty __before__ in BaseController, putting "common" logic into
> BaseController.__call__ and never overriding __call__ in subclasses.
I don't have this problem, but I see where you're coming from. Just
shoving stuff in BaseController.__call__ does make sense. If you
really want to *force* the user to call BaseController's __before__
and __after__ methods, throw some assertion statements into
BaseController's __call__ method:
assert getattr(self, "_base_controller_before_called", False), \
"Dummy, you forgot to call BaseController.__before__!"
Then, in BaseController's __before__ method, you just make sure to set
that attribute.
I find that using assertions in this way is a great way to keep
subclasses "honest" ;) It's good policy to put assertions in places
where you know the user is likely to mess up.
Best Regards,
-jj
--
http://jjinux.blogspot.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---