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? 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". I'm specifically interested in form data here, which is why I haven't used the REQUEST['thingo'] idiom, so I suspect I must be accessing REQUEST incorrectly. Any clues would be most welcome (if only someone could write a ZenOfZope product; I'd download it into my brain in an instant! :-) Regards, Daryl Tester
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
Michel Pelletier wrote:
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.
I keep forgetting that Zope is a collection of products :-(. One day, I do intend to spend more quality time with the source and how the components interact.
Well, hanging is probably not the best way for Zope to handle this situation, why it hangs I couldn't tell you
Oddly, it only appears to do that when I call the external method directly. If I place <dtml-var "frobnicate(REQUEST)"> (modified to pass in REQUEST explicitly) into a Method or Document and request that without parameters, it comes up immediately and correctly. Odd.
(perhaps you should post that to the collector).
Will do.
However, form data usualy comes from a POST, and here your doing a GET, passing a query string.
Ahh, differing semantics. I'm used to Python's cgi.py (and Perl's cgi.pm, from memory) treating POSTs and GETs with query strings the same. The only way of telling the difference was by looking at the REQUEST_METHOD (if you cared enough, that is).
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.
This was my concern - REQUEST's namespace seems a little crowded, and I was worried about clashing identifiers. Hold the phone! I've just constructed a document that basically does <dtml-var REQUEST>, and invoked it with a query string, and the parameters DO show up in REQUEST.form. Are you pulling the wool over my eyes, Michel? :-) Regards, Daryl Tester PS - The recent "Virtual folders / URL" thread solution you proposed was _very_ enlightening, but yet reading about direct traversal in the ZSQL manual didn't provide anywhere near the same lightbulb factor. Could Digital Creations consider adding that in as an example?
participants (2)
-
Daryl Tester -
Michel Pelletier