I add this method to my SitePage for setting cookies:
def setCookie(self, key, value, path='/', expires='ONCLOSE',
cookie = Cookie(key, value)
if expires == 'ONCLOSE' or not expires:
pass # this is already default behavior
elif expires == 'NOW' or expires == 'NEVER':
t = time.gmtime(time.time())
if expires == 'NEVER':
t = (t + 10,) + t[1:]
t = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT", t)
cookie.setExpires(t.strftime("%a, %d-%b-%Y %H:%M:%S GMT", t))
This assumes you are using mxDateTime -- it would be nice to support the
DateTimeDelta type as well. I don't think I ever use anything but
ONCLOSE and NEVER, though.
On Tue, 2002-03-19 at 19:06, Matt Feifarek wrote:
> I'm starting to use Webkit.Cookie and I'm frustrated that the expires method
> only takes a string, rather than a python date/time float.
> Of course one can use time.time() and some string substitution etcetera to
> accomplish the same thing, but it would be nice to have capabilities like...
> chocolateChip.setExpires( time.time() ) # expires a cookie now
> chocolateChip.setExpires( time.time() + 30*24*60*60 ) # expires a cookie in
> 30 days
> it might be even nicer if one could do something like this:
> chocolateChip.setExpires( "+1w" ) # expires a cookie one week from now
> chocolateChip.setExpires( "+240s" ) # expires a cookie 240 seconds from now
> chocolateChip.setExpires( 0 ) # expires a cookie now (in the past)
> I would be happy to change this code and submit it for inclusion if there is
> interest. I don't know what the formal submission procedures are.
> Webware-discuss mailing list