How to write and read array from cookie in Pylons

How to write and read array from cookies ?

The easiest way to write an array in cookie is serialize it using pickle module and quote returned string with urllib module. For example:

import pickle, urllib
cookie = []
response.set_cookie('some_cookie', urllib.quote(pickle.dumps(cookie)))

And getting an array from cookie:

cookie = pickle.loads(str(urllib.unquote(request.cookies['some_cookie'])))

Share and Enjoy:
  • Google Bookmarks
  • Twitter
  • BLIP - Bardzo Lubię Informować Przyjaciół
  • pinger.pl - Nie taki zwykły blog.
  • Facebook
  • del.icio.us
  • Digg
  • Wrzuć to na Flakera - powiadom swoich Znajomych
  • grono.net - internetowa społeczność przyjaciół
  • Netvibes
  • LinkedIn
  • Technorati
  • Dodaj niusa « OSnews.pl

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment