-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Can someone tell me what I'm doing wrong? I have the VERY simple external methods test.xm and test2.xm defined. They are: from DateTime import DateTime def dwTime(self): t=DateTime() return DateTime.timeTime(t) def dwName(self,REQUEST=None): return "%s" % REQUEST['AUTHENTICATED_USER'] They both work fine from the Zope/manage screen using the 'try-it' tab. When I use them in a test file: <!--#var standard_html_header--> <!--#var test.xm--> <!--#var test2.xm--> <!--#var standard_html_footer--> The first (<!--#var test.xm-->) works just fine. but the addition of the second, causes the following run-time error: Traceback (innermost last): File /usr/local/Zope-1.9.0-src/lib/python/ZPublisher/Publish.py, line 879, in publish_module File /usr/local/Zope-1.9.0-src/lib/python/ZPublisher/Publish.py, line 595, in publish (Info: /test_area/test1) File /usr/local/Zope-1.9.0-src/lib/python/OFS/Document.py, line 181, in __call__ (Object: test1) File /usr/local/Zope-1.9.0-src/lib/python/OFS/Document.py, line 177, in __call__ (Object: test1) File /usr/local/Zope-1.9.0-src/lib/python/DocumentTemplate/DT_String.py, line 514, in __call__ (Object: test1) File /usr/local/Zope-1.9.0-src/lib/python/Products/ExternalMethod/ExternalMethod.py, line 266, in __call__ (Object: Item) (Info: ((), {}, (None,))) TypeError: (see above) - --------------------------------------------- A computer without Microsoft products is like a dog without bricks chained to its head - --------------------------------------------- -----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Comment: Processed by Mailcrypt 3.5.1, an Emacs/PGP interface Charset: noconv iQA/AwUBNsnKG9tGhckXZmDjEQJJpwCfeziCLyeaVw0/h3FfcAE2JJ3uQrQAoNbJ E+U2HC4yTS/aZQmJb0XO6YLk =ApHz -----END PGP SIGNATURE-----
I can't readily explain why this is the case, but it looks like either a) REQUEST is not being passed in, or b) REQUEST is None The following method: def dwName(self,REQUEST=None): if REQUEST is not None: return "%s" % REQUEST['AUTHENTICATED_USER'] else: return "" will run. It will produce the desired result if called directly (by going to the URL of the method). It does not seem to produce anything when called from a DTML Method. And that's as much as I know :) Kevin On Tue, Feb 16, 1999 at 01:42:21PM -0600, David Wagle wrote: ,----- | -----BEGIN PGP SIGNED MESSAGE----- | Hash: SHA1 | | | Can someone tell me what I'm doing wrong? | | I have the VERY simple external methods test.xm and test2.xm | defined. | | They are: | | from DateTime import DateTime | | def dwTime(self): | t=DateTime() | return DateTime.timeTime(t) | | def dwName(self,REQUEST=None): | return "%s" % REQUEST['AUTHENTICATED_USER'] | | They both work fine from the Zope/manage screen using the | 'try-it' tab. | | When I use them in a test file: | | <!--#var standard_html_header--> | | <!--#var test.xm--> | <!--#var test2.xm--> | | <!--#var standard_html_footer--> | | The first (<!--#var test.xm-->) works just fine. | but the addition of the second, causes the following | run-time error: | | | | | Traceback (innermost last): | File /usr/local/Zope-1.9.0-src/lib/python/ZPublisher/Publish.py, line 879, in publish_module | File /usr/local/Zope-1.9.0-src/lib/python/ZPublisher/Publish.py, line 595, in publish | (Info: /test_area/test1) | File /usr/local/Zope-1.9.0-src/lib/python/OFS/Document.py, line 181, in __call__ | (Object: test1) | File /usr/local/Zope-1.9.0-src/lib/python/OFS/Document.py, line 177, in __call__ | (Object: test1) | File /usr/local/Zope-1.9.0-src/lib/python/DocumentTemplate/DT_String.py, line 514, in __call__ | (Object: test1) | File /usr/local/Zope-1.9.0-src/lib/python/Products/ExternalMethod/ExternalMethod.py, line 266, in __call__ | (Object: Item) | (Info: ((), {}, (None,))) | TypeError: (see above) | | | | | - --------------------------------------------- | A computer without Microsoft products is like | a dog without bricks chained to its head | - --------------------------------------------- | -----BEGIN PGP SIGNATURE----- | Version: PGP for Personal Privacy 5.0 | Comment: Processed by Mailcrypt 3.5.1, an Emacs/PGP interface | Charset: noconv | | iQA/AwUBNsnKG9tGhckXZmDjEQJJpwCfeziCLyeaVw0/h3FfcAE2JJ3uQrQAoNbJ | E+U2HC4yTS/aZQmJb0XO6YLk | =ApHz | -----END PGP SIGNATURE----- | | _______________________________________________ | Zope maillist - Zope@zope.org | http://www.zope.org/mailman/listinfo/zope `----- -- Kevin Dangoor UUnet Technologies kid@ans.net / 734-214-7349
At 01:42 PM 2/16/99 -0600, David Wagle wrote:
def dwName(self,REQUEST=None): return "%s" % REQUEST['AUTHENTICATED_USER']
They both work fine from the Zope/manage screen using the 'try-it' tab. ... When I use them in a test file:
<!--#var standard_html_header-->
<!--#var test.xm--> <!--#var test2.xm-->
The problem is a common one. Invoking a method via a URL is *not* the same as invoking a method by using the var tag in DTML. This can be confusing, so let me say it again--the ORB does not call objects in the same way DTML calls objects. Invoking a method via a URL is handled by the Zope ORB. It is the process of object publishing. It involves object traversal rules, argument marshalling, etc. Invoking a method via DTML is handled by the DocumentTemplate classes. It is subject to moderately complex namespace and rendering rules. In general the ORB will pass arguments to your method when it is published by looking for them in the HTTP request. In general, DTML will simply call a method without passing any arguments to it. (Note: DTML Documents and Methods are an exception to the rule, and are handled specially by both the ORB and DTML) DTML is calling your dwName method like this dwName(), while the ORB is calling it like this dwName(REQUEST=REQUEST). One solution is to call dwName from DTML like so: <!--#var "dwName(REQUEST)"--> Another solution is to not get the REQUEST from the arguments. This way your method can be called both from DTML and from the ORB. def dwName(self,REQUEST=None): "find the authenticated user" if REQUEST is None and hasattr(self,'REQUEST'): REQUEST=self.REQUEST return "%s" % self.REQUEST['AUTHENTICATED_USER'] This works because Zope makes the current request available as a instance attribute. (Whoops, another Zope secret comes out ;-) Hope this helps. -Amos
Amos Latteier writes:
At 01:42 PM 2/16/99 -0600, David Wagle wrote:
When I use them in a test file:
<!--#var standard_html_header-->
<!--#var test.xm--> <!--#var test2.xm-->
The problem is a common one.
Invoking a method via a URL is *not* the same as invoking a method by using the var tag in DTML.
Ok - all this made a great deal of sense, and I felt I was armed with some good info . . .but . . .
Another solution is to not get the REQUEST from the arguments. This way your method can be called both from DTML and from the ORB.
def dwName(self,REQUEST=None): "find the authenticated user" if REQUEST is None and hasattr(self,'REQUEST'): REQUEST=self.REQUEST return "%s" % self.REQUEST['AUTHENTICATED_USER']
This works. . . .
ummm, no it doesn't . . . dwName is defined EXACTLY as you have it here. It is located in the ./Extentions directory in the file dwxm.py. test2.xm is defined as an external method that calls dwName from that file. test.xm calls dwTime from that file. Again, <!--#var test2.xm--> bombs. doing <!--#var "dwName()"--> dies as well. Again calling it from the external methods tab works just fine. What am I missing. --------------------------------------------- A computer without Microsoft products is like a dog without bricks chained to its head --------------------------------------------- -- --------------------------------------------- A computer without Microsoft products is like a dog without bricks chained to its head --------------------------------------------- -- --------------------------------------------- A computer without Microsoft products is like a dog without bricks chained to its head ---------------------------------------------
Ok -- here's some more info. when I call the script <!--#var standard_html_header--> <!--#var test.xm--> <!--#var "REQUEST['AUTHENTICATED_USER']"--> <!--#var standard_html_footer--> I get the correct, expected results. When I add one line so that it reads: <!--#var standard_html_header--> <!--#var test.xm--> <!--#var "REQUEST['AUTHENTICATED_USER']"--> <!--#var "dwName(REQUEST)"--> <!--#var standard_html_footer--> I get a traceback. This traceback includes a whole ton of REQUEST data like so: Traceback (innermost last): File /usr/local/Zope-1.9.0-src/lib/python/ZPublisher/Publish.py, line 879, in publish_module ....[snip]... environ: SCRIPT_NAME: '/Zope' UNIQUE_ID: 'Nsn4OcauaW4AAAQhCbQ' HTTP_ACCEPT_ENCODING: 'gzip' PCGI_EXE: '/usr/bin/python' HTTP_ACCEPT_LANGUAGE: 'en' PCGI_PUBLISHER: '/usr/local/Zope-1.9.0-src/pcgi/pcgi_publisher.py' GATEWAY_INTERFACE: 'CGI/1.1' PCGI_DISPLAY_ERRORS: '1' HTTP_ACCEPT: 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*' REQUEST_URI: '/Zope/test_area/test1' SCRIPT_URL: '/Zope/test_area/test1' .....[snip].... What is interesting is AUTHENTICATED_USER is NOT there. Now, IF I am right, that this is showing me the entire REQUEST structure that was passed to my external method, why is it different from teh one being used INSIDE the dtml where AUTHENTICATED_USER is available? --------------------------------------------- A computer without Microsoft products is like a dog without bricks chained to its head ---------------------------------------------
participants (3)
-
Amos Latteier -
David Wagle -
Kevin Dangoor