By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,929 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,929 IT Pros & Developers. It's quick & easy.

cookie

P: n/a
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

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Jul 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Ajay <ab******@mail.usyd.edu.au> writes:
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
Jul 18 '05 #2

P: n/a
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
Quoting "John J. Lee" <jj*@pobox.com>:
Ajay <ab******@mail.usyd.edu.au> writes:
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
--
http://mail.python.org/mailman/listinfo/python-list

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Jul 18 '05 #3

P: n/a
Ajay <ab******@mail.usyd.edu.au> writes:
Quoting "John J. Lee" <jj*@pobox.com>:
Ajay <ab******@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
Jul 18 '05 #4

P: n/a

Quoting "John J. Lee" <jj*@pobox.com>:
Ajay <ab******@mail.usyd.edu.au> writes:
Quoting "John J. Lee" <jj*@pobox.com>:
Ajay <ab******@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 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

John
--
http://mail.python.org/mailman/listinfo/python-list

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Jul 18 '05 #5

P: n/a
Ajay <ab******@mail.usyd.edu.au> writes:
[...]
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
Jul 18 '05 #6

P: n/a
In <ma**************************************@python.o rg>, Ajay wrote:
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
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.