reading cookies from external methods
This is probably a silly question, but how does one read cookies from an external method without passing REQUEST to the method? The method should be callable both from dtml and from other external methods. I know I can do this: def foo(REQUEST): cookie = REQUEST.get('some_cookie') return cookie Can I get the same cookie without requiring boty my dtml methods and my other scripts and external methods that call foo() to be able to pass the REQUEST object? I'd like other methods to be able to say this: val = foo() # good without requiring them to be able to do this: val = foo(REQUEST) # bad Likewise, I'd much rather say this: <dtml-var foo> <!-- good --> than this: <dtml-var expr="foo(RESPONSE)"> <!-- bad --> If I've just revealed myself to be tremendously ignorant of the right way of doing all these things in Zope, great! Please enlighten me. Thanks for any tips, j -- Jed Parsons Industrial Light + Magic (415) 746-2974 grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6))))}},(split(//, "++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0. What!?")));
+-------[ Jed Parsons ]---------------------- | | This is probably a silly question, but how does one read cookies from an | external method without passing REQUEST to the method? | | The method should be callable both from dtml and from other external | methods. | | I know I can do this: | | def foo(REQUEST): | cookie = REQUEST.get('some_cookie') | return cookie | | Can I get the same cookie without requiring boty my dtml methods and my | other scripts and external methods that call foo() to be able to pass | the REQUEST object? | | I'd like other methods to be able to say this: | | val = foo() # good | | without requiring them to be able to do this: | | val = foo(REQUEST) # bad | | Likewise, I'd much rather say this: | | <dtml-var foo> <!-- good --> | | than this: | | <dtml-var expr="foo(RESPONSE)"> <!-- bad --> | | If I've just revealed myself to be tremendously ignorant of the right | way of doing all these things in Zope, great! Please enlighten me. | Thanks for any tips, def foo(context): cookie = context.REQUEST.get('some_cookie') return cookie <dtml-var foo> should pass in the current context. Although it's been a while since I played with dtml. -- Andrew Milton akm@theinternet.com.au
----- Original Message ----- From: "Jed Parsons" <jedp@ilm.com> To: <zope@zope.org> Sent: Friday, March 31, 2006 2:04 PM Subject: [Zope] reading cookies from external methods
This is probably a silly question, but how does one read cookies from an external method without passing REQUEST to the method?
The method should be callable both from dtml and from other external methods.
I know I can do this:
def foo(REQUEST): cookie = REQUEST.get('some_cookie') return cookie
You just need to access REQUEST from within your external method, eg: def foo(self, otherparms...) REQUEST = self.REQUEST cookie = REQUEST.get('some_cookie') That should do it! HTH Jonathan
Oh, cool. That's kind of magical. :) It looks like I can't get the RESPONSE that way, so if I want to do a RESPONSE.setCookie(...) somewhere, I have to pass REQUEST and RESPONSE as before, yes? Thanks much, j Jonathan wrote:
----- Original Message ----- From: "Jed Parsons" <jedp@ilm.com> To: <zope@zope.org> Sent: Friday, March 31, 2006 2:04 PM Subject: [Zope] reading cookies from external methods
This is probably a silly question, but how does one read cookies from an external method without passing REQUEST to the method?
The method should be callable both from dtml and from other external methods.
I know I can do this:
def foo(REQUEST): cookie = REQUEST.get('some_cookie') return cookie
You just need to access REQUEST from within your external method, eg:
def foo(self, otherparms...)
REQUEST = self.REQUEST cookie = REQUEST.get('some_cookie')
That should do it!
HTH
Jonathan
-- Jed Parsons Industrial Light + Magic (415) 746-2974 grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6))))}},(split(//, "++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0. What!?")));
Hi, that's well documented in the Zope Book : http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/view Short answer : request = context.REQUEST response = request.RESPONSE Regards, Patrick. On 3/31/06, Jed Parsons <jedp@ilm.com> wrote:
Oh, cool. That's kind of magical. :)
It looks like I can't get the RESPONSE that way, so if I want to do a RESPONSE.setCookie(...) somewhere, I have to pass REQUEST and RESPONSE as before, yes?
Thanks much, j
Jonathan wrote:
----- Original Message ----- From: "Jed Parsons" <jedp@ilm.com> To: <zope@zope.org> Sent: Friday, March 31, 2006 2:04 PM Subject: [Zope] reading cookies from external methods
This is probably a silly question, but how does one read cookies from an external method without passing REQUEST to the method?
The method should be callable both from dtml and from other external methods.
I know I can do this:
def foo(REQUEST): cookie = REQUEST.get('some_cookie') return cookie
You just need to access REQUEST from within your external method, eg:
def foo(self, otherparms...)
REQUEST = self.REQUEST cookie = REQUEST.get('some_cookie')
That should do it!
HTH
Jonathan
-- Jed Parsons Industrial Light + Magic (415) 746-2974
grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6))))}},(split(//, "++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0. What!?"))); _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Isn't that for scripts and not extensions (external methods)? Patrick Decat wrote:
Hi,
that's well documented in the Zope Book : http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/view
Short answer : request = context.REQUEST response = request.RESPONSE
Regards, Patrick.
On 3/31/06, Jed Parsons <jedp@ilm.com> wrote:
Oh, cool. That's kind of magical. :)
It looks like I can't get the RESPONSE that way, so if I want to do a RESPONSE.setCookie(...) somewhere, I have to pass REQUEST and RESPONSE as before, yes?
Thanks much, j
Jonathan wrote:
----- Original Message ----- From: "Jed Parsons" <jedp@ilm.com> To: <zope@zope.org> Sent: Friday, March 31, 2006 2:04 PM Subject: [Zope] reading cookies from external methods
This is probably a silly question, but how does one read cookies from an external method without passing REQUEST to the method?
The method should be callable both from dtml and from other external methods.
I know I can do this:
def foo(REQUEST): cookie = REQUEST.get('some_cookie') return cookie
You just need to access REQUEST from within your external method, eg:
def foo(self, otherparms...)
REQUEST = self.REQUEST cookie = REQUEST.get('some_cookie')
That should do it!
HTH
Jonathan
-- Jed Parsons Industrial Light + Magic (415) 746-2974
grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6))))}},(split(//, "++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0. What!?"))); _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Jed Parsons Industrial Light + Magic (415) 746-2974 grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6))))}},(split(//, "++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0. What!?")));
Jed Parsons wrote:
Oh, cool. That's kind of magical. :)
It looks like I can't get the RESPONSE that way, so if I want to do a RESPONSE.setCookie(...) somewhere, I have to pass REQUEST and RESPONSE as before, yes?
No, RESPONSE is a subobject of REQUEST - see python scripts as an example :-) Regards Tino
Awesome thank you, j Tino Wildenhain wrote:
Jed Parsons wrote:
Oh, cool. That's kind of magical. :)
It looks like I can't get the RESPONSE that way, so if I want to do a RESPONSE.setCookie(...) somewhere, I have to pass REQUEST and RESPONSE as before, yes?
No, RESPONSE is a subobject of REQUEST - see python scripts as an example :-)
Regards Tino
-- Jed Parsons Industrial Light + Magic (415) 746-2974 grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6))))}},(split(//, "++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0. What!?")));
--On 31. März 2006 11:04:59 -0800 Jed Parsons <jedp@ilm.com> wrote:
Can I get the same cookie without requiring boty my dtml methods and my other scripts and external methods that call foo() to be able to pass the REQUEST object?
The REQUEST object is usually an attribute of the current context object. Means you can access it at context.REQUEST, here.REQUEST ...depending where you need to access it. Inside an external method you can use self.REQUEST as long as the first argument of the external method is called 'self'. -aj ----------------------------------------------------------------------- - Andreas Jung ZOPYX Ltd. & Co KG - - E-mail: info@zopyx.com Web: www.zopyx.com, www.zopyx.de - -----------------------------------------------------------------------
participants (6)
-
Andreas Jung -
Andrew Milton -
Jed Parsons -
Jonathan -
Patrick Decat -
Tino Wildenhain