[Tutor] cookie expiration date format
Tim Johnson
tim at johnsons-web.com
Sat Mar 17 15:25:04 CET 2007
On Saturday 17 March 2007 08:13, Tim Johnson wrote:
> On Saturday 17 March 2007 02:31, Luke Paireepinart wrote:
> > Tim Johnson wrote:
> > > 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()
>
> I shouldn't have used the word 'datatype', 'cuz I'm sure that it is a
> string. -having built cookie functions "from scratch" in other languages,
> according to RFC 2965.
> I think I found what I am looking for at
> http://pleac.sourceforge.net/pleac_python/cgiprogramming.html
> and look for keyword
> time_format
>
> I'll try and implement later today and report back on success or failure
> Thanks Luke
Here we go....
import datetime
time_format = "%a, %d %b %Y"
expires = "%s" % ((datetime.datetime.now()
+ datetime.timedelta(-1)).strftime(time_format))
# ^
# -1 references previous day -----------|
Thus the cookie directive in toto looks something like this:
note that it should all on one line so I'm delimiting with two lines of
asterisks
************************************************************************
Set-Cookie: kbcpCookie=" (password|mypwd)(mylogin)";
Domain=.linus.johnson.com; expires=Fri, 16 Mar 2007; Path=/cgi-bin/
************************************************************************
I don't think the rfc is touchy about spaces following semicolons, but the
exact format of the date (minutes and seconds optional) is important
Just a comment:
I've used python for years and am always impressed with the
great amount of resources and the care taken to vet and document libraries,
but I must say, in the case of the cookies library, module `Cookie', that the
documentation is a bit lacking and could use more, and some examples - as
well.
MTCW
Tim
--
Tim Johnson <tim at johnsons-web.com>
Palmer, Alaska, USA
More information about the Tutor
mailing list