summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Florenzano <floguy@gmail.com>2009-10-29 02:26:26 -0700
committerEric Florenzano <floguy@gmail.com>2009-10-29 02:26:26 -0700
commit6281f549be6cefbaca011726395cf1cd4b8f8fa9 (patch)
treeda5c4f9354b04330ad47a14f0405906374ee8ed3
parent43cb2c22bc121d397cd6136a6dfbaa5fc244fa03 (diff)
downloadpystache-6281f549be6cefbaca011726395cf1cd4b8f8fa9.tar.gz
Compile the regular expression once and re-use it for the render_sections bit
-rw-r--r--pystache/template.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/pystache/template.py b/pystache/template.py
index 317e0a6..bb56523 100644
--- a/pystache/template.py
+++ b/pystache/template.py
@@ -1,5 +1,7 @@
import re
+SECTION_RE = re.compile(r"{{\#([^\}]*)}}\s*(.+?)\s*{{/\1}}", re.M | re.S)
+
class Template(object):
tag_types = {
None: 'tag',
@@ -20,8 +22,7 @@ class Template(object):
def render_sections(self, template, context):
"""Expands sections."""
- regexp = re.compile(r"{{\#([^\}]*)}}\s*(.+?)\s*{{/\1}}", re.M | re.S)
- match = re.search(regexp, template)
+ match = SECTION_RE.search(template)
while match:
section, section_name, inner = match.group(0, 1, 2)
@@ -37,7 +38,7 @@ class Template(object):
template = template.replace(section, inner)
else:
template = template.replace(section, '')
- match = re.search(regexp, template)
+ match = SECTION_RE.search(template)
return template