Graham Dumpleton
grahamd at dscpl.com.au
Mon Oct 3 18:42:10 EDT 2005
Jorey Bump wrote .. > Graham Dumpleton wrote: > > > > On 04/10/2005, at 4:18 AM, Jorey Bump wrote: > > > >> and/or use conventional Python exceptions to handle errors: > >> > >> try: > >> a = req.form['myvar'] > >> except KeyError, key: > >> return '<h1>No form variable by that name: %s</h1>' % (key,) > > > > This unfortunately doesn't help with mod_python.publisher unless you > are > > prepared to throw away its abilities to automatically decode form > > parameters into function arguments. > > I am prepared to do so, and have for a long time. :) Personal preferences. Personally, I don't use publisher at all because of various other warts. :-) Either way, if one wants to hack up something quickly, using function arguments for the form parameters is simply easier. > Nonetheless, I'm > not sure why you think this is unhelpful with Publisher. As long as you > take req and the automatically decoded parameter in your function, you > can refer to them both ways: > > def compare(req, myvar): > if req.form['myvar'] == myvar: > return 'they are the same' > else: > # this should never happen > return 'they are not the same' Except that that code will never get a chance to execute when "myvar" was never supplied as a form argument in the first place, which if I recollect was what the original question related to. Graham
|