cookie

A

Ajay

hi!

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?

i am creating the cookie as follows:
data = "user:" + username + "&access:" + access + "&expiry:" + str(expTime)
cookie_digest = hmac.new(key, data).digest()
cookie = Cookie.SimpleCookie()
cookie_data = data + "&digest:" + cookie_digest
cookie["um_cookie"] = cookie_data
cookie["um_cookie"]["path"] = "/~abrar1/hons/interface/admin/"
print cookie

thanks
cheers
 
J

John J. Lee

Ajay said:
hi!

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.


John
 
A

Ajay

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?

cheers
 
J

John J. Lee

Ajay said:
Quoting "John J. Lee said:
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:

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
 
A

Ajay

Quoting "John J. Lee said:
Ajay said:
Quoting "John J. Lee said:
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:

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 believe you. i didn't think it would make a difference. and i agree that
the Cookie module preserves quotes across the parse->output cycle
my question is
import Cookie
c = Cookie.SimpleCookie()
c["test"]= "blah"
print c Set-Cookie: test=blah;
c["test"] = "blah" + "testing"
print c Set-Cookie: test=blahtesting;
str = "testing blah"
c["test"] = str
print c
Set-Cookie: test="testing blah";

why does the final print statement have the quotes. Note i haven't put
str='"testing blah"'. if i had done that i would understand the quotes
there.
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.
yes i should probably read that :)
it doesn't though mention anything about the above behaviour

cheers
 
J

John J. Lee

Ajay said:
i believe you. i didn't think it would make a difference. and i agree that
the Cookie module preserves quotes across the parse->output cycle
my question is
import Cookie
c = Cookie.SimpleCookie()
c["test"]= "blah"
print c Set-Cookie: test=blah;
c["test"] = "blah" + "testing"
print c Set-Cookie: test=blahtesting;
str = "testing blah"
c["test"] = str
print c
Set-Cookie: test="testing blah";

why does the final print statement have the quotes. Note i haven't put
str='"testing blah"'. if i had done that i would understand the quotes
there.

Does the following help?

Python 2.4a2 (#5, Aug 5 2004, 22:07:01)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import Cookie
c = Cookie.SimpleCookie()
c["test"] = "testingblah"
print c Set-Cookie: test=testingblah;
c["test"] = "testing blah"
print c Set-Cookie: test="testing blah";


John
 
M

Marc 'BlackJack' Rintsch

my question is
import Cookie
c = Cookie.SimpleCookie()
c["test"]= "blah"
print c Set-Cookie: test=blah;
c["test"] = "blah" + "testing"
print c Set-Cookie: test=blahtesting;
str = "testing blah"
c["test"] = str
print c
Set-Cookie: test="testing blah";

why does the final print statement have the quotes. Note i haven't put
str='"testing blah"'. if i had done that i would understand the quotes
there.

It's no difference if you bind the string to a name or assign it directly,
it's the contents of the string:
import Cookie
c = Cookie.SimpleCookie()
c["test"] = "spaceless"
print c Set-Cookie: test=spaceless;
c["test"] = "not spaceless"
print c
Set-Cookie: test="not spaceless";

Ciao,
Marc 'BlackJack' Rintsch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top