summaryrefslogtreecommitdiff
path: root/pystache
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-05-05 16:23:50 -0700
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-05-05 16:23:50 -0700
commit5dd7fa7c8df7f186abda7ac463c44fc70953cc27 (patch)
tree1ef5eb072129f7c2637f3bc78584bcec995e5c1f /pystache
parent01a2daf493d23fe8058ed64c522ddbe301b50db8 (diff)
downloadpystache-5dd7fa7c8df7f186abda7ac463c44fc70953cc27.tar.gz
Moved the default delimiters into pystache.defaults.
Diffstat (limited to 'pystache')
-rw-r--r--pystache/defaults.py3
-rw-r--r--pystache/parser.py20
-rw-r--r--pystache/tests/test_parser.py3
3 files changed, 16 insertions, 10 deletions
diff --git a/pystache/defaults.py b/pystache/defaults.py
index a510cfe..0a20328 100644
--- a/pystache/defaults.py
+++ b/pystache/defaults.py
@@ -38,6 +38,9 @@ STRING_ENCODING = sys.getdefaultencoding()
# strings that arise from files.
FILE_ENCODING = sys.getdefaultencoding()
+# The delimiters to start with when parsing.
+DELIMITERS = (u'{{', u'}}')
+
# How to handle missing tags when rendering a template.
MISSING_TAGS = MissingTags.ignore
diff --git a/pystache/parser.py b/pystache/parser.py
index 5215c64..9bfc30c 100644
--- a/pystache/parser.py
+++ b/pystache/parser.py
@@ -1,39 +1,41 @@
# coding: utf-8
"""
-Provides a class for parsing template strings.
-
-This module is only meant for internal use by the renderengine module.
+Exposes a parse() function to parse template strings.
"""
import re
+from pystache.defaults import DELIMITERS
from pystache.parsed import ParsedTemplate
-DEFAULT_DELIMITERS = (u'{{', u'}}')
END_OF_LINE_CHARACTERS = [u'\r', u'\n']
NON_BLANK_RE = re.compile(ur'^(.)', re.M)
+# TODO: add some unit tests for this.
def parse(template, delimiters=None):
"""
Parse a unicode template string and return a ParsedTemplate instance.
+ Arguments:
+
+ template: a unicode template string.
+
+ delimiters: a 2-tuple of delimiters. Defaults to the package default.
+
"""
parser = _Parser(delimiters)
return parser.parse(template)
-def _compile_template_re(delimiters=None):
+def _compile_template_re(delimiters):
"""
Return a regular expresssion object (re.RegexObject) instance.
"""
- if delimiters is None:
- delimiters = DEFAULT_DELIMITERS
-
# The possible tag type characters following the opening tag,
# excluding "=" and "{".
tag_types = "!>&/#^"
@@ -184,7 +186,7 @@ class _Parser(object):
def __init__(self, delimiters=None):
if delimiters is None:
- delimiters = DEFAULT_DELIMITERS
+ delimiters = DELIMITERS
self._delimiters = delimiters
diff --git a/pystache/tests/test_parser.py b/pystache/tests/test_parser.py
index 4aa0959..92248ea 100644
--- a/pystache/tests/test_parser.py
+++ b/pystache/tests/test_parser.py
@@ -7,6 +7,7 @@ Unit tests of parser.py.
import unittest
+from pystache.defaults import DELIMITERS
from pystache.parser import _compile_template_re as make_re
@@ -19,7 +20,7 @@ class RegularExpressionTestCase(unittest.TestCase):
Test getting a key from a dictionary.
"""
- re = make_re()
+ re = make_re(DELIMITERS)
match = re.search("b {{test}}")
self.assertEqual(match.start(), 1)