[Zope] External Methods and REQUEST

Michel Pelletier michel@digicool.com
Thu, 16 Mar 2000 20:02:04 -0800


Daryl Tester wrote:
> 
> Greetings,
> 
> I've started having a serious fiddle with External Methods, and have
> run across a couple of brain issues:
> 
> 1)  Most examples I've seen (well, both :-) pass REQUEST as a parameter
> in addition to self (for example, def frobnicate(self, REQUEST)).  Yet
> I've noticed that I can pull REQUEST out of self's namespace, and they
> appear identical.  Is there a reason for passing in REQUEST explicitly?

Being explicit.  Also, your method might not (depending on how you use
it) be being called from ZPublisher (in which case REQUEST is not
passed, it must be acquired), then again, your method might not be in an
acquisition context either, in which case you must pass it.  In 99% of
the cases however, you can do either.
 
> 2)  (And if this is related to point #1, then you may beat me around the
> head with a Nerf bat).  I defined an external method called frobnicate
> as follows:
> 
> def frobnicate(self):
>     "One of many test functions"
>     return self.REQUEST.form
> 
> and install it.  If I call it with http://localhost/zope/frobnicate?foo=bar
> it returns a dictionary of {'foo' : 'bar'}, as it should.  If I call
> it without any arguments as http://localhost/zope/frobnicate the
> browser hangs and eventually times out with "The document contained no
> data". 

Well, hanging is probably not the best way for Zope to handle this
situation, why it hangs I couldn't tell you (perhaps you should post
that to the collector).  However, form data usualy comes from a POST,
and here your doing a GET, passing a query string.

> I'm specifically interested in form data here, which is why I
> haven't used the REQUEST['thingo'] idiom,

You can still get form data that way, the form attribute of REQUEST is
when you want to make sure you're definatly getting a value from a form
and not some other namespace.

-Michel