From 5dd7fa7c8df7f186abda7ac463c44fc70953cc27 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Sat, 5 May 2012 16:23:50 -0700 Subject: Moved the default delimiters into pystache.defaults. --- pystache/parser.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'pystache/parser.py') 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 -- cgit v1.2.1