[Zope] reading cookies from external methods

Andrew Milton akm at theinternet.com.au
Fri Mar 31 14:07:31 EST 2006


+-------[ 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 at theinternet.com.au


More information about the Zope mailing list