[Zope] Anyone got some code that takes a dictionary and encodes it intoa cookie?

Chris McDonough chrism@zope.com
Wed, 3 Oct 2001 10:02:24 -0400

The marshal module may help here... it'll get you as far as serializing the
dict to a string at least.

>>> d = {'1':'foo', '2':'bar'}
>>> import marshal
>>> marshal.dumps(d)
>>> marshal.loads(marshal.dumps(d))
{'2': 'bar', '1': 'foo'}

This is marginally more secure than using pickle because marshal is more
restricted as to what it can serialize.  From the python docs:

The following types are supported: None, integers, long integers, floating
point numbers, strings, Unicode objects, tuples, lists, dictionaries, and
code objects, where it should be understood that tuples, lists and
dictionaries are only supported as long as the values contained therein are
themselves supported; and recursive lists and dictionaries should not be
written (they will cause infinite loops).

----- Original Message -----
From: "Tony McDonald" <tony.mcdonald@ncl.ac.uk>
To: "Zope" <zope@zope.org>
Sent: Wednesday, October 03, 2001 9:30 AM
Subject: [Zope] Anyone got some code that takes a dictionary and encodes it
intoa cookie?

> ...and vice versa?
> I've searched google, the NIPltd archives, the Zope site and python.org
> no success.
> I'd like to use CST for this as it works *very* sweetly, but I'm still
> having major brain flips trying to tie up the CST with ZEO using the
> storages that are about, and I've decided to use this *dreadful* hack
> I can get my head around CST again.
> Cheers,
> Tone.
> --
> Dr Tony McDonald,  Assistant Director, FMCC, http://www.fmcc.org.uk/
> The Medical School, Newcastle University Tel: +44 191 243 6140
> A Zope list for UK HE/FE  http://www.fmcc.org.uk/mailman/listinfo/zope
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )