diff options
Diffstat (limited to 'grc/gui/Utils.py')
-rw-r--r-- | grc/gui/Utils.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py index 90ebde03b3..f20e3c0fa6 100644 --- a/grc/gui/Utils.py +++ b/grc/gui/Utils.py @@ -101,19 +101,26 @@ def encode(value): return gobject.markup_escape_text(valid_utf8) -def parse_template(tmpl_str, **kwargs): - """ - Parse the template string with the given args. - Pass in the xml encode method for pango escape chars. - - Args: - tmpl_str: the template as a string - - Returns: - a string of the parsed template - """ - kwargs['encode'] = encode - return str(Template(tmpl_str, kwargs)) +class TemplateParser(object): + def __init__(self): + self.cache = {} + + def __call__(self, tmpl_str, **kwargs): + """ + Parse the template string with the given args. + Pass in the xml encode method for pango escape chars. + + Args: + tmpl_str: the template as a string + + Returns: + a string of the parsed template + """ + kwargs['encode'] = encode + template = self.cache.setdefault(tmpl_str, Template.compile(tmpl_str)) + return str(template(namespaces=kwargs)) + +parse_template = TemplateParser() def align_to_grid(coor): |