Loading a Cookie from a Dictonary

  • Thread starter Michael Sampson
  • Start date
M

Michael Sampson

I'm using the Cookie module.
Say I have something that looks like this

import Cookie
c = Cookie.Cookie()
c.load(aDictonary)

What would the format of aDictornary be, I've looked around the net and I
can only find examples on how to format the input to load if it is a string.
The best info on this I could find is

Loading cookies from a dictionary 'd'
is equivalent to calling:
map(Cookie.__setitem__, d.keys(), d.values())


I just need a few examples with multiple cookies and I should be able to
figure it out from there.
Thanks,
-Michael
 
J

John J. Lee

Michael Sampson said:
I'm using the Cookie module.
Say I have something that looks like this

import Cookie
c = Cookie.Cookie()
c.load(aDictonary)

What would the format of aDictornary be, I've looked around the net and I
can only find examples on how to format the input to load if it is a string.
The best info on this I could find is
[...]

What are you actually trying to accomplish?

Server? Client?


John
 
M

Michael Sampson

John J. Lee said:
Michael Sampson said:
I'm using the Cookie module.
Say I have something that looks like this

import Cookie
c = Cookie.Cookie()
c.load(aDictonary)

What would the format of aDictornary be, I've looked around the net and I
can only find examples on how to format the input to load if it is a string.
The best info on this I could find is
[...]

What are you actually trying to accomplish?

Server? Client?


John


Assume I have a server trying to create a cookie to send to the browser.
Instead of making the cookies one at a time like

c = Cookie.Cookie()

c['firstname'] = 'joe'

c['lastname'] = 'samson'

c['lastname'][max-age] = 3600

I want to be able to store the info for the cookies in one dictonary and
pass that to the constructor for Cookie(), or load it into the cookie using
c.load().
 
J

John J. Lee

Michael Sampson said:
news:[email protected]... [...]
Assume I have a server trying to create a cookie to send to the browser.
Instead of making the cookies one at a time like

c = Cookie.Cookie()

You probably want Cookie.SimpleCookie instead.

c['firstname'] = 'joe'

c['lastname'] = 'samson'

c['lastname'][max-age] = 3600

I want to be able to store the info for the cookies in one dictonary and
pass that to the constructor for Cookie(), or load it into the cookie using
c.load().

There's no method to call to do that, AFAIK. Just write a function
that does exactly what you write above (only getting the keys and
values from the dict, of course: you want a "name" and "value" key as
well as "max-age", etc., I guess, with values in this case "lastname"
and "samson").


John
 

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
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top