[Zope] Parameter puzzle

Martijn Pieters mj@digicool.com
Wed, 22 Mar 2000 09:37:24 +0100


On Wed, Mar 22, 2000 at 08:46:19AM +0100, Mark Andrew wrote:
> Hi Zopistas
> 
> while trying to make gtk's (very useful) Boring Product (slightly
> more) interesting, I came across the following (for me) strange
> behaviour.
> 
> manage_ methods seem to always have "REQUEST=None" as their last
> parameter. If I remove the "=None" from manage_edit then I notice no
> difference, so the actual parameter is presumably being passed.
> However if remove the complete formal parameter (and the reference to
> REQUEST in the body of the method) 
> 
> def manage_edit(self, title): 
>         """does this really need a doc string?"""
>         self.title = title
> #	if REQUEST is not None:
> #	    return MessageDialog(
> #		title = 'Edited',
> #		message = "Properties for %s changed." % self.id,
> #		action = './manage_main',
> #		)
> 
> 
> then everything still works ! Why is python not complaining about a
> parameter mismatch ?

Because Zope passes in those parameters that the method asks for. If you take
away the REQUEST parameter, Zope simply doesn't pass it in.

The manage_ methods use REQUEST=None to make sure you can use the methods in
situations there is no REQUEST to pass in. You can call manage_edit with a new
title, and have it still work, from a DTML Method without having to pass in
the REQUEST object, as you won't need the MessageDialog anyway.

-- 
Martijn Pieters
| Software Engineer    mailto:mj@digicool.com
| Digital Creations  http://www.digicool.com/
| Creators of Zope       http://www.zope.org/
|   The Open Source Web Application Server
---------------------------------------------