[Zope-dev] Cookie with dictionary as content

Dieter Maurer dieter@handshake.de
Sun, 10 Jun 2001 18:37:52 +0200 (CEST)


florian_reiser@gmx.de writes:
 > I'm developing the ZPivotTable product. For implementing the drilldown
 > mechanism, I need to store the information about which columns and rows
 > are open in a cookie. I thougt of storing this information in form of
 > a dictionary, which would be stored in a cookie.
 > 
 > The dictionary consists of several lists, containing the open columns
 > or rows.
 > 
 > Could you give me a tip how i can store the dictionary in the cookie.
 > I've already tried to converting it to a string and converting the string
 > back, when needed.
When forming the cookie value,
convert the dict into a string (with the "repr" function) and then
encode it (either URL-quote or Base 64), to avoid characters
not allowed in cookie values.

To transform the cookie value into a dictionary again,
decode the value and then eval it.
You will need an External Method for the "eval" part,
as "eval" is not exposed to DTML.


Be carefull! "eval" on untrusted strings is a severe security
risk. Use "eval(str,{'__builtins__':None})".
This will disable all Python builtins for evaluation, among
them the dangerous ones, such as "open", "__import__", ...


Dieter