[Zope] ZClass question - array of arrays

Tino Wildenhain tino@wildenhain.de
Mon, 16 Sep 2002 15:53:45 +0200


Hi Dianne,

> Hi,
>
> I'm having a little bit of a problem working out what ZClass property I
> should be setting.  I want to record an array that can either contain
> strings or more arrays.
>
> eg:
>
> It can be
>
> ['a', 'b', 'c']
>
> or
>
> ['a', ['b', 'c'], 'd']
>
> or
>
> [['a','b'], ['c','d'], ['e','f']]
>
> The problem is that I can't work out what property type I should be
> setting this to be.  I tried tokens, but tokens won't allow arrays to be
> saved, and both lines and strings assume that there will be a string
> (obviously), which means that I have to do a lot of splitting on [ and ,
> before I can work with the data.  The whole idea of the property is that
> if there is a scalar in position X, it shows the scalar, otherwise with
> an array, it shows a random value from that array.
>
> Is there an obvious type that I am missing?

No, this is currently not possible to store other datatypes in properties.
You can however try to write your own "plugin" property but then you
have to work out the code in several places. If you try it, you will
get at least great insight on the internal structure of Zope and the heads
of the developers and their timepressure ;))

If you dont like it so hard, just convert it to a string, like repr()
does or more complicated: StringIO,pickle and base64encode/-decode
and save it as a string property. This has the advantage of beeing able
to store and retrive even thru a html-form. (The use in html-forms
is the force behind the current implementation. But then I think we miss
at least the propertytype for :record or :records which are mapped to
dictionaries. )

HTH
Tino Wildenhain