[stringtemplate-interest] Bug in PyST: fails to look for templates in supergroup [patch]
Benjamin Niemann
pink at odahoda.de
Sun Sep 21 11:37:32 PDT 2008
Hi Roman,
On Wed, Aug 13, 2008 at 7:09 PM, Roman Odaisky <roma at qwertty.com> wrote:
> Greetings,
>
> I failed to find the proper place to report bugs for the Python version of
> StringTemplate, so I'll report it here.
>
> PyST fails to look for templates in supergroups.
>
> To reproduce:
>
> mkdir -p /tmp/ST/sub
> echo '$var:inner()$' >/tmp/ST/outer.st
> echo 'it = $it$' >/tmp/ST/sub/inner.st
>
> python <<E
> from stringtemplate3 import StringTemplateGroup
> stg_sub = StringTemplateGroup("brochure_common", "/tmp/ST/sub")
> stg = StringTemplateGroup("brochure", "/tmp/ST", superGroup=stg_sub)
> st = stg.getInstanceOf("outer")
> st["var"] = "hello"
> print str(st) # or unicode(st)
> E
>
> I get an error message (why doesn't PyST propagate the original exception?!).
I agree that the exception should bubble up to the caller. Fixed.
> Expected: "it = hello".
>
> To fix: grep for "eek", agree with the comment, place "return None" instead
> of "raise". Though it's not a proper fix, because it would return None also
> in the (rare) case "br.close()" throws an exception.
>
> StringTemplateGroup.lookupTemplate expects loadTemplateFromBeneathRootDir to
> return None in case the template file is not found, while the latter throws
> an exception instead.
Took a while, but I just submitted a fix for the bug. loadTemplate now
returns None, if the file does not exist. I think that other errors,
e.g. permissions, etc., should not cause ST look continue searching in
super groups.
-Ben
More information about the stringtemplate-interest
mailing list