cookie
John J. Lee
jjl at pobox.com
Fri Aug 27 15:05:08 EDT 2004
Ajay <abra9823 at mail.usyd.edu.au> writes:
> Quoting "John J. Lee" <jjl at pobox.com>:
> > Ajay <abra9823 at mail.usyd.edu.au> writes:
[...]
> > > i am printing a simple cookie, but instead of printing
> > > um=name:blah&access:admin&exp:2312390.909
> > >
> > > its printing
> > > um="name:blah&access:admin&exp:2312390.909"
> > >
> > > why the quotes?
> >
> > Why not?
> >
> > I don't see how they'd cause any harm.
> >
> they dont cause any harm, except for a an extra statement removing those
> quotes when i read the cookie, parse it and authenticate the session.
> the question is - is that normal cookie behaviour?
> cookie["test"]="blah"
> print cookie
>
> prints test=blah and not test="blah"
> so why the quotes when i do the same thing, but use a variable instead of a
> string literal?
You've lost me, but on the basis of a very quick test, the Cookie
module preserves quotes across the parse->output cycle:
>>> import Cookie
>>> c = Cookie.SimpleCookie()
>>> c.load('foo=bar')
>>> print c
Set-Cookie: foo=bar;
>>> c.load('foo="bar"')
>>> print c
Set-Cookie: foo="bar";
>>>
That seems sensible behaviour to me, since quotes around cookie values
are significant for Netscape cookies (ie. regular, vanilla, internet
cookies).
I can categorically state that using a variable name instead of a
string literal will make no difference whatsoever. I think you're
actually confused about Python syntax rather than the workings of the
Cookie module. Try reading the Python language tutorial at
www.python.org.
John
More information about the Python-list
mailing list