Possible namespace bug in template.py

1 view
Skip to first unread message

Martin

unread,
Aug 30, 2007, 11:21:33 AM8/30/07
to brevé template engine, li...@martinpp.co.uk

Hi again,

Just stumbled across what might be a small bug when using namespaces.
It seems that if you define a namespace, but don't define any vars in
a call to render then you get a KeyError for the namespace. Looking at
the code it seems that the Namespace object is only created for T.vars
when vars exist although the _g variable always tries to reference
T.vars[ns] if namespace is defined.

A fix would be duplicating the namespace creation check in vars for
_gs.
E.g.

_g = { }
_g.update (T.tags)
if ns:
/* Get KeyError if the following two lines are omitted
and a namespace is specified whilst vars is None */
if not T.vars.has_key ( ns ):
T.vars [ ns ] = Namespace ( )
/* End */
_g [ ns ] = T.vars [ ns ]
else:
_g.update (T.vars)

Apologies in advance if this isn't a bug and I have just go it wrong
somewhere.

Martin

Cliff Wells

unread,
Aug 31, 2007, 2:59:15 PM8/31/07
to breve-...@googlegroups.com, li...@martinpp.co.uk
On Thu, 2007-08-30 at 08:21 -0700, Martin wrote:

> A fix would be duplicating the namespace creation check in vars for
> _gs.
> E.g.
>
> _g = { }
> _g.update (T.tags)
> if ns:
> /* Get KeyError if the following two lines are omitted
> and a namespace is specified whilst vars is None */
> if not T.vars.has_key ( ns ):
> T.vars [ ns ] = Namespace ( )
> /* End */
> _g [ ns ] = T.vars [ ns ]
> else:
> _g.update (T.vars)
>

I'll take a look at this. It might just be viable to use {} rather than
None for the default value of vars.

Cliff

Reply all
Reply to author
Forward
0 new messages