commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 01/04: grc: cache compiled Cheetah template


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/04: grc: cache compiled Cheetah templates
Date: Fri, 11 Dec 2015 20:27:01 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch maint
in repository gnuradio.

commit b8a2ea29ffbb280cc0dbbdf84c150e165a3b0ab3
Author: Sebastian Koslowski <address@hidden>
Date:   Thu Dec 10 11:47:48 2015 +0100

    grc: cache compiled Cheetah templates
---
 grc/gui/Utils.py | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py
index 90ebde0..f20e3c0 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):



reply via email to

[Prev in Thread] Current Thread [Next in Thread]