[ZPT] nested access to object data

Jamie Heilman jamie at audible.transient.net
Thu May 8 03:25:14 EDT 2003


Andreas Jung wrote:
> I have class X:
> 
> class X:
> 
>   _data1 = {}
>   _data2 = {}
> 
> and I want to access the dictionaries from within a ZPT like 
> "here/data1/key1" or "here/data2/key2".
> Is this possible? What is the best way to implement this?

class X:
  _data1 = data1 = {}
  _data2 = data2 = {}

Works, but I'm skeptical that its the best way as that leaves that
structure open to modification by python scripts.  Maybe a computed
attribute that returns _dataN.copy()?  I haven't tried that but it
might be slick.  I generally 2 step it like:

PERM = "bar"
class X:
  _foo = {}
  security.declareProtected(PERM, "getFoo")
  def getFoo(self): return self._foo.copy()

Then call it as define="foo here/getFoo" content="foo/key".

-- 
Jamie Heilman                   http://audible.transient.net/~jamie/
"Paranoia is a disease unto itself, and may I add, the person standing
 next to you may not be who they appear to be, so take precaution."
						-Sathington Willoughby



More information about the ZPT mailing list