Re: [Zope] DTML namespace puzzle
Ron Bickers writes:
I have a Python Script (sendOrder) that calls a DTML method (orderMessage) as follows:
container.orderMessage(num=num, SESSION=SESSION)
orderMessage contains the following:
<dtml-with "SESSION['info']" mapping> Order Number: <dtml-var num> Blah blah other session variables that work fine. </dtml-with>
I get a KeyError on num. If I modify orderMessage to contain the following, it works:
<dtml-let num=num> <dtml-with "SESSION['info']" mapping> Order Number: <dtml-var num> Blah blah other session variables that work fine. </dtml-with> </dtml-let>
This seems strange to me. What am I missing? I failed to reproduce this in my Zope CVS.
It is puzzling indeed! Does "SESSION['info']" has a key "num" or do you expect to access the "num" passed as parameter? In this case, it might have something to do with permissions, as Zope sometimes turns insufficient permissions into KeyError. However, I expect your "SESSION['info']" is a standard dictionary and then access should by unprotected. Dieter
-----Original Message----- From: Dieter Maurer [mailto:dieter@handshake.de] Sent: Sunday, January 28, 2001 3:43 PM To: Ron Bickers Cc: zope@zope.org Subject: Re: [Zope] DTML namespace puzzle
Does "SESSION['info']" has a key "num" or do you expect to access the "num" passed as parameter? In this case, it might have something to do with permissions, as Zope sometimes turns insufficient permissions into KeyError. However, I expect your "SESSION['info']" is a standard dictionary and then access should by unprotected.
SESSION['info'] does not have a key "num". The only num is passed as a parameter. Did you use SQLSession to try to reproduce it, or just another mapping? Could SQLSession have something to do with it? _______________________ Ron Bickers Logic Etc, Inc. rbickers@logicetc.com
Ron Bickers writes:
method(num=num SESSION=session): <dtml-with "SESSION['INFO']" mapping> <dtml-var num> </dtml-with> raises KeyError "num". .... SESSION['info'] does not have a key "num". The only num is passed as a parameter. Did you use SQLSession to try to reproduce it, or just another mapping? Could SQLSession have something to do with it? No, I did not use SQLSession but used a normal dictionary.
However, nothing should be able to hide "num" in the way you described. The DTML namespace is a stack of mappings. When the method is called, the keyword parameter dict is pushed onto this stack. The <dtml-with> pushes "SESSION['INFO']" onto the stack. When "num" is looked up, the namespace asks each mapping on the stack (from top to bottom) whether it knows "num". The first that does, wins. The only thing, I could imagine, were that "SESSION['INFO']" contained a num, but the user does not have access to its value. However, this is incompatible with your observation that: <dtml-let num=num> <dtml-with "SESSION['INFO']" mapping> <dtml-var num> </dtml-with> </dtml-let> worked. The only difference between the two pieces of code is that the working code as an additional mapping between the keyword parameter dict and the "dtml-with" dict. It appears as if some magic would pop a frame from the namespace stack. SQLSession can't do it as it does not get hold of the namespace. "dtml-with" could but it is very strange that it should do such things and especially that it does for you but not for me. Dieter
-----Original Message----- From: Dieter Maurer [mailto:dieter@handshake.de] Sent: Monday, January 29, 2001 1:17 PM To: Ron Bickers Cc: zope@zope.org Subject: RE: [Zope] DTML namespace puzzle
of the namespace. "dtml-with" could but it is very strange that it should do such things and especially that it does for you but not for me.
I have no explanation whatsoever, but I removed the dtml-let and it's working now. Sigh... This leads me to a related question, however. I realized the DTML method call from the Python Script included 'container' as the first parameter (as shown below). I did this so that the DTML method could find another method in the same Folder. Without it, it fails with a NameError. I realized that I don't understand how Python Scripts can/should call DTML methods. That is, are there magical parameters? Why does the following 'container' parameter work? msg = container.orderMessage(container, num=num, SESSION=SESSION) _______________________ Ron Bickers Logic Etc, Inc. rbickers@logicetc.com
Ron Bickers writes:
.... I realized the DTML method call from the Python Script included 'container' as the first parameter (as shown below).... I don't understand how Python Scripts can/should call DTML methods. That is, are there magical parameters?... About a week ago, I posted a short description on how parameters are passed to DTML objects to this list.
Take a look at the archive. Dieter
It was posted to zope-dev, which I should probably subscribe to. http://lists.zope.org/pipermail/zope-dev/2001-January/009018.html Thank you! Exactly what I needed. _______________________ Ron Bickers Logic Etc, Inc. rbickers@logicetc.com
-----Original Message----- From: Dieter Maurer [mailto:dieter@handshake.de]
About a week ago, I posted a short description on how parameters are passed to DTML objects to this list.
Take a look at the archive.
participants (2)
-
Dieter Maurer -
Ron Bickers