Re: [Zope-dev] Why is TemplateDict so opaque? -and- Have you seen this problem?
Dave Parker wrote [sorry folks, I'm tired, so this is halfway to a rant :-( ]
it's ok. I was wandering around the office kicking things and looking dazed a couple of weeks ago when I finally delved into this stuff.
I'm not happy that I now know what TemplateDict is - I really wish I hadn't had to go there, but now that I'm there I have a much better understanding of why it is impossible to get information out of it; it has "do you have this key" and "get the value of this key" and absolutely nothing else.
The problem is that it's implemented as a multimapping. To do keys(), items(), &c you'd have to walk the multimapping and search each object. I guess you could simply do something like this (untested, written from just looking at the MultiMapping.c code. Probably could be implemented far more easily...) t = templatedictobj l = [] while 1: try: l.append(t.pop()) except IndexError: break # l now has the dictionaries from the namespace stack l.reverse() d = {} for i in l: d.update(i) t.push(i) print d.items(), d.keys(), d.values() this code just pops all the namespace objects off the multimapping, stores them in a list, merges them together and pushes them back onto the multimapping. it's horribly inefficient. and probably buggy. :) Anthony
Anthony Baxter wrote:
The problem is that it's implemented as a multimapping. To do keys(), items(), &c you'd have to walk the multimapping and search each object.
Yeah, I saw that in there, but the thing is it's not like I'd want to use that for anything else other than trying to figure out what is going on in the namespace. You'd be able to do so much with that extra bit of information when you get a traceback, for instance. Right now it's so opaque as to be frightening (hey, what are you hiding, man?!?) ;-)
participants (2)
-
Anthony Baxter -
Dave Parker