Edgewall Software

Opened 15 years ago

Last modified 8 years ago

#331 new defect

Context collection is not iterable

Reported by: anatoly techtonik <techtonik@…> Owned by: cmlenz
Priority: major Milestone: 0.9
Component: General Version: 0.5.1
Keywords: Cc:

Description

While collaborating on Genshi debugging template it has been found that Context is not iterable and can not be inspected conveniently from template.

${locals()['__data__']} reveals that local variables are gathered into some kind of list (see repr() definition, but Context object is closer to a dictionary. But it is not a dictionary either, because the following prints keys in dict:

${"\n".join(dict(a="zxc", b="bsa"))}

But the same stuff with locals()['__data__'] produces error:

${'\n'.join(locals()['__data__'])}

File "m:\p\trac\trac-0.11dev\trac\timeline\templates\timeline.rss", 
line 19, in <Expression u"'\\n'.join(locals()['__data__'])"> 
  ${'\n'.join(locals()['__data__'])} 
File "m:\p\trac\genshi-0.5dev\genshi\template\base.py", line 184, in 
__getitem__ 
  raise KeyError(key) 

Change History (3)

comment:1 Changed 15 years ago by cmlenz

  • Milestone changed from 0.6 to 0.7

comment:2 in reply to: ↑ description Changed 15 years ago by Carsten Klein <carsten.klein@…>

This is due to the fact that internally Context stores all context data, which are actually of type dict, in a so-called deque.

This is mainly used for allowing stacking of contexts and the way the template code is being executed.

So, when trying to access the dictionary that is associated with frame[0], which is the currently executed frame, you would have to access the dict that is stored in that frame.

Basically like so

print ctxt.frames[0]

will return the information that you want.

As such I would not call it a defect...

comment:3 Changed 8 years ago by hodgestar

  • Milestone changed from 0.7 to 0.9

Moved to milestone 0.9.

Note: See TracTickets for help on using tickets.