Passing namespace from DTML to Python Script
Hi, I want to call a python script from DTML and pass the namespace, the trouble is, the PS needs to be called from a python expression in DTML. So, taking the simple DTML method: <dtml-var standard_html_header> <dtml-let test_thang="'Test Thang'"> <dtml-var "test_ps" html_quote> </dtml-let> <dtml-var standard_html_footer> ...and a simple python script (with namespace bound to _): return _['test_thang'] ..which of coruse, doesn't work, it gives me: <PythonScript instance at 01B17ED0> ..so change <dtml-var "test_ps" html_quote> to <dtml-var "test_ps()" html_quote> and now I get: Error type: KeyError Error value: test_thang ...fair enough thinks me, I need to do the old dtml trick and so change to: <dtml-var "test_ps(_.None,_)" html_quote> ...and now I get: Error type: TypeError Error value: no arguments expected ...OK, irritating, but lets try changing the parameter list to 'context, _': Finally I get what I want: Test Thang However, now I want to call it somewhere else as just <dtml-var test_ps>, I get: Error type: TypeError Error value: not enough arguments; expected 2, got 0 ...at this point my head exploded and I thought I'd mail the list. Can anyone explain how Ishould eb doing this? cheers, Chris
Hi Chris My initial guess would have been to try: return context._['test_thang'] I thought context gave you access to the namespace. Am I wrong? On Thu, May 24, 2001 at 10:51:41AM +0100, Chris Withers wrote:
Hi,
I want to call a python script from DTML and pass the namespace, the trouble is, the PS needs to be called from a python expression in DTML.
So, taking the simple DTML method: <dtml-var standard_html_header> <dtml-let test_thang="'Test Thang'"> <dtml-var "test_ps" html_quote> </dtml-let> <dtml-var standard_html_footer>
...and a simple python script (with namespace bound to _): return _['test_thang']
..which of coruse, doesn't work, it gives me: <PythonScript instance at 01B17ED0>
..so change <dtml-var "test_ps" html_quote> to <dtml-var "test_ps()" html_quote> and now I get: Error type: KeyError Error value: test_thang
...fair enough thinks me, I need to do the old dtml trick and so change to: <dtml-var "test_ps(_.None,_)" html_quote> ...and now I get: Error type: TypeError Error value: no arguments expected
...OK, irritating, but lets try changing the parameter list to 'context, _': Finally I get what I want: Test Thang
However, now I want to call it somewhere else as just <dtml-var test_ps>, I get: Error type: TypeError Error value: not enough arguments; expected 2, got 0
...at this point my head exploded and I thought I'd mail the list. Can anyone explain how Ishould eb doing this?
cheers,
Chris
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- ------------------------------------------------------ Andres Corrada-Emmanuel Email: andres@corrada.com Internet Programming http://www.mamey.com ------------------------------------------------------
From: "Chris Withers" <chrisw@nipltd.com>
I want to call a python script from DTML and pass the namespace, the trouble is, the PS needs to be called from a python expression in DTML.
So, taking the simple DTML method: <dtml-var standard_html_header> <dtml-let test_thang="'Test Thang'"> <dtml-var "test_ps" html_quote>
Why the quotes around test_ps?
</dtml-let> <dtml-var standard_html_footer>
...and a simple python script (with namespace bound to _): return _['test_thang']
..which of coruse, doesn't work, it gives me: <PythonScript instance at 01B17ED0>
This should work if you just use <dtml-var test_ps html_quote>. Cheers, Evan @ digicool
Evan Simpson wrote:
From: "Chris Withers" <chrisw@nipltd.com>
I want to call a python script from DTML and pass the namespace, the trouble is, the PS needs to be called from a python expression in DTML.
So, taking the simple DTML method: <dtml-var standard_html_header> <dtml-let test_thang="'Test Thang'"> <dtml-var "test_ps" html_quote>
Why the quotes around test_ps?
Because this is a simplification that demonstrates the problem nicely ;-) <dtml-var "('<TD BGCOLOR=%s> </TD>' % bgcolor(???))*(nav_indent_level-1)"> ...is the real thing, where bg color is the Python Script. The workaround I have is: <dtml-let bgcolor=bgcolor> <dtml-var "('<TD BGCOLOR=%s> </TD>' % bgcolor)*(nav_indent_level-1)"> </dtml-let> ...which is kinda sucky :-S How should I be calling a python script from a python expression in DTML and passing the namesapce in the process? cheers, Chris
From: "Chris Withers" <chrisw@nipltd.com>
How should I be calling a python script from a python expression in DTML and passing the namesapce in the process?
Ah, I see. If you're binding the caller's namespace to "_", then you can use "python_method(_=_)". Normally the parameter list of a Script determines its call signature; The single exception to the rule is this use of the namespace binding as a keyword argument. Cheers, Evan @ digicool
Evan Simpson wrote:
From: "Chris Withers" <chrisw@nipltd.com>
How should I be calling a python script from a python expression in DTML and passing the namesapce in the process?
Ah, I see. If you're binding the caller's namespace to "_", then you can use "python_method(_=_)".
Ahh, thankyou, thankyou :-)) Hmmm, this should be documented somewhere in big flashing lights for stupid people like me... ...but, is it just me, or is the above not very intuitive? python_method(_) would be more so, but I see the problems. Hmmm, I suppose this is DTML though ;-) cheers, Chris
participants (3)
-
andresï¼ corrada.com -
Chris Withers -
Evan Simpson