summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Florenzano <floguy@gmail.com>2009-10-29 02:32:43 -0700
committerEric Florenzano <floguy@gmail.com>2009-10-29 02:32:43 -0700
commit554606075b3652bc3f00fcabcde464f05faec4a4 (patch)
treea37d3edb107b3df0c5322f444687f7bb5b08f681
parent126757068ea6466f6d61c7c4e3f4095f5aa4bec8 (diff)
downloadpystache-554606075b3652bc3f00fcabcde464f05faec4a4.tar.gz
Avoid code duplication by restructuring loops slightly
-rw-r--r--pystache/template.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/pystache/template.py b/pystache/template.py
index 584a5fe..f7b620e 100644
--- a/pystache/template.py
+++ b/pystache/template.py
@@ -23,8 +23,11 @@ class Template(object):
def render_sections(self, template, context):
"""Expands sections."""
- match = SECTION_RE.search(template)
- while match:
+ while 1:
+ match = SECTION_RE.search(template)
+ if match is None:
+ break
+
section, section_name, inner = match.group(0, 1, 2)
if section_name in context and context[section_name]:
if hasattr(context[section_name], '__iter__'):
@@ -38,14 +41,16 @@ class Template(object):
template = template.replace(section, inner)
else:
template = template.replace(section, '')
- match = SECTION_RE.search(template)
return template
def render_tags(self, template, context):
"""Renders all the tags in a template for a context."""
- match = TAG_RE.search(template)
- while match:
+ while 1:
+ match = TAG_RE.search(template)
+ if match is None:
+ break
+
tag, tag_type, tag_name = match.group(0, 1, 2)
func = 'render_' + self.tag_types[tag_type]
@@ -53,8 +58,6 @@ class Template(object):
replacement = getattr(self, func)(tag_name, context)
template = template.replace(tag, replacement)
- match = TAG_RE.search(template)
-
return template
def render_tag(self, tag_name, context):