Reposting to zope-dev because no answers on the zope list. Hi all, I have some questions. Say I have a external method/product method return_vars which I call from a form: def return_vars(self, var=None, **kw): return "var: %s, kw: %s" % (var,kw) Is it correct that any passed form variable besides "var" will get lost, i.e. that ZPublisher will _not_ marshall the other variables into the method call? If so, why? Is this a python limitation? I played around with co_varnames and python doesn't seem to offer a possibility to recognize **kw as something special. Where does this marshalling happen, in ZPublisher/mapply.py? TIA, oliver
On Wednesday 02 Oct 2002 9:31 am, Oliver Bleutgen wrote:
Hi all, I have some questions. Say I have a external method/product method return_vars which I call from a form:
def return_vars(self, var=None, **kw): return "var: %s, kw: %s" % (var,kw)
Is it correct that any passed form variable besides "var" will get lost,
It wont be copied into kw.
i.e. that ZPublisher will _not_ marshall the other variables into the method call?
Would you really want all of them? All those that come from query string? http headers? cookies? environment variables? You can get sane access to all of these through the REQUEST parameter. Im sure you know that.
Where does this marshalling happen, in ZPublisher/mapply.py?
yes
Toby Dickenson wrote:
On Wednesday 02 Oct 2002 9:31 am, Oliver Bleutgen wrote:
i.e. that ZPublisher will _not_ marshall the other variables into the method call?
Would you really want all of them? All those that come from query string? http headers? cookies? environment variables?
Only form variables. But you're right, this would be inconsistent.
You can get sane access to all of these through the REQUEST parameter. Im sure you know that.
Yes, I know. The problem at hand was the invokeFactory method from the CMF (1.1), which only has id as a parameter, but not title, preventing me from using it directly with a form which also wants to set the title. My workaround is to use a "proxy" method which has title as a named parameter. Thanks, oliver
If so, why?
I see that Toby and you answered that.
Is this a python limitation?
No.
I played around with co_varnames and python doesn't seem to offer a possibility to recognize **kw as something special.
def foo(bar, **kw): ... pass ... foo.func_code.co_flags 11
def foo(bar, *args): ... pass ... foo.func_code.co_flags 7
def foo(bar): ... pass ... foo.func_code.co_flags 3
-- Steve Alexander
Oliver Bleutgen <myzope@gmx.net> wrote:
def return_vars(self, var=None, **kw): return "var: %s, kw: %s" % (var,kw)
Is it correct that any passed form variable besides "var" will get lost, i.e. that ZPublisher will _not_ marshall the other variables into the method call?
Very often, to allow calling of some scripts from a form or from another script, I end up using the idiom: def somescripts(self, foo, bar, REQUEST=None, **kw) # or: ##parameters=foo, bar, REQUEST=None, **kw if REQUEST is not None: kw.update(REQUEST.form) ... Florent -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
participants (4)
-
Florent Guillaume -
Oliver Bleutgen -
Steve Alexander -
Toby Dickenson