[Zope] Delete value from REQUEST

Lennart Regebro regebro at nuxeo.com
Thu Jan 22 06:48:43 EST 2004


Ashley wrote:
> I found some time ago this little external method posted by Daryl Tester:
> 
> ===========================================================
> def removeRequest(REQUEST, item):
>     "Remove an item from a REQUEST.form"
>     try:
>         del REQUEST.form[item]
>     except:
>         pass
>     return None
> ===========================================================
> 
> This obviously did not work straight away for this particular item, since it
> was in the cookies section of REQUEST

Yes, that method should rather look like this:

     def delRequestVar(self, req, name):
         # No errors of any sort may propagate, and we don't care *what*
         # they are, even to log them.
         try: del req.other[name]
         except: pass
         try: del req.form[name]
         except: pass
         try: del req.cookies[name]
         except: pass
         try: del req.environ[name]
         except: pass

That is how CookieCrumbler defines it.

> This initially appears to work fine. I call the external method from within
> a page, and then view REQUEST while still on the same page, and theClient
> has disappeared. However, if I subsequently go to any other page it is still
> there.

That's because the cookie is sent with each request by the client. 
Deleteing it from the request will only delete it from THAT request.

> I have tried RESPONSE.expireCookie(item) in the external method, and Zope
> didn't seem to appreciate that!
 >
 > \\Zope\\lib\\python\\ZPublisher\\HTTPRequest.py",
 > line 1194, in __getattr__\n raise AttributeError, key\n',
 > 'AttributeError: expireCookie\n'

Looks like you did REQUEST.expireCookie() instead.




More information about the Zope mailing list