[Zope] Cookies in Python

Gilles Lenfant gilles@pilotsystems.net
Wed, 2 Oct 2002 17:14:32 +0200


----- Original Message -----
From: "Juan Manuel Ruiz García" <jmruiz@lab.it.uc3m.es>
To: <zope@zope.org>
Sent: Wednesday, October 02, 2002 2:21 PM
Subject: [Zope] Cookies in Python


> Hi,
>
> I need to know if there is any way to set and read cookies from python
> scripts.I try to import Cookies module but Zope doesn't allow me to do
that.

You don't need to import cookies. Just do this in a python script to write a
cookie.

== SNIP ==
...
howManyDays = 7
cookieName = 'mycookie'
cookieValue = 'myValue'
RESPONSE = context.REQUEST.RESPONSE
dateexp = (DateTime() + howManyDays).toZone('GMT').rfc822()
RESPONSE.setCookie(cookieName, cookieValue, expires=dateexp, path='/')
...
== /SNIP ==

To read a cookie...

cookieValue = context.REQUEST.cookies.get('mycookie', None)


>
> I'm using Zope 2.3.
>
> Thanks in advance.
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>
>