[Tutor] cookie expiration date format
Mike Hansen
Mike.Hansen at atmel.com
Mon Mar 19 16:33:02 CET 2007
> -----Original Message-----
> From: tutor-bounces at python.org
> [mailto:tutor-bounces at python.org] On Behalf Of Luke Paireepinart
> Sent: Friday, March 16, 2007 8:31 PM
> To: Tim Johnson
> Cc: tutor at python.org
> Subject: Re: [Tutor] cookie expiration date format
>
> Tim Johnson wrote:
> > Hi:
> > I want to be able to expire a cookie programmatically.
> > In other languages, I just set the expiration date to 'yesterday'.
> > If I look at the documentation at:
> > http://docs.python.org/lib/node644.html
> > for the Cookie object, I see the following:
> > -----------------------------------------------------------
> > expires
> > Integer expiry date in seconds since epoch,
> > -----------------------------------------------------------
> > I'm not clear what datatype is needed here.
> > Can anyone clarify this for me?
> >
> Sounds like it's an integer or float, such as returned by time.time()
> >>> import time
> >>> time.time()
> 1174098190.796 #seconds since epoch
> >>> _ / 60
> 19568303.179933332#minutes since epoch
> >>> _ / 60
> 326138.3863322222 #hours ..
> >>> _ / 24
> 13589.099430509259# days
> >>> _ / 365.25
> 37.204926572236161 #years
> >>> .205 * 1.2
> 0.24599999999999997 #months ( fractional part of year )
> >>>
>
> So today is 37 years 2.5 months from January 1, 1970.
> 1970 + 37 = 2007, and January 1 + 2.5 months = March 16.
>
> If you wanted the cookie to expire 24 hours from now,
> time.time() + 3600 * 24 #(seconds in a day)
>
> See http://en.wikipedia.org/wiki/Unix_epoch for more info on
> the epoch.
> look into the time and the datetime modules, there should be
> an easy way
> to find the seconds since epoch for whatever date you want.
> HTH,
> -Luke
Some of the modules in the Python standard library make things a little
more difficult than other languages.(Perl, Ruby, ...) This is a good
example of it. Are there any 3rd party modules that let you set the
expiration date to 'yesterday'? I know I could write a wrapper, but I'd
rather not re-invent the wheel and save some time.
Another example is ftplib. Other language's ftp modules/libraries allow
you do something like sendaciifile(fh) or sendbinaryfile(fh) yet you
need to build your own wrapper functions in Python.
http://effbot.org/librarybook/ftplib.htm
Mike
More information about the Tutor
mailing list