Cookies / CGI

Oleg Broytmann phd at phd.russ.ru
Mon May 29 04:14:27 EDT 2000


On Sun, 28 May 2000, Timothy O'Malley wrote:
> Oleg Broytmann <phd at phd.russ.ru> wrote:
> > # ----- create -----
> > #! /usr/local/bin/python -O
> > 
> > def set_cookie():
> >    import time
> >    t = time.gmtime(time.time())
> >    t = (t[0] + 10,) + t[1:] # add 10 years :)
> > 
> >    import Cookie
> >    cookie = Cookie.Cookie()
> > 
> >    cookie["id"] = str(1024)
> >    cookie["id"]["expires"] = time.strftime("%a, %d-%b-%Y %T GMT", t)
> 
> 
> You don't have to format the time string yourself.  Cookie.py will
> do it for you.  Just set the value to the number of seconds:
> 
> 
>    cookie["id"]["expires"] = 10 * 365 * 24 * 3600

   The program was written in a haste, a little while before I really read
Cookie.py (excellent work, Tim!) and understand it. :)

   You can also mention I don't need to cast the value itself into string:
cookie["id"] = 1024
   instead of
cookie["id"] = str(1024)

   and Cookie.py will use pickle to dump/load the value. Beware of broken
pikles!

Oleg.            (All opinions are mine and not of my employer)
---- 
    Oleg Broytmann      Foundation for Effective Policies      phd at phd.russ.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list