Permalink
Browse files

moved environment defaults to jinja2.defaults

--HG--
branch : trunk
  • Loading branch information...
1 parent f3c35c4 commit 4f5008ff1917356e0d71bedc96546cf0c5db834d @mitsuhiko mitsuhiko committed May 23, 2008
Showing with 34 additions and 33 deletions.
  1. +6 −2 jinja2/defaults.py
  2. +11 −11 jinja2/environment.py
  3. +17 −20 jinja2/ext.py
View
@@ -8,20 +8,24 @@
:copyright: 2007-2008 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
-from jinja2.filters import FILTERS as DEFAULT_FILTERS
-from jinja2.tests import TESTS as DEFAULT_TESTS
from jinja2.utils import generate_lorem_ipsum
+# defaults for the parser / lexer
BLOCK_START_STRING = '{%'
BLOCK_END_STRING = '%}'
VARIABLE_START_STRING = '{{'
VARIABLE_END_STRING = '}}'
COMMENT_START_STRING = '{#'
COMMENT_END_STRING = '#}'
LINE_STATEMENT_PREFIX = None
+TRIM_BLOCKS = False
+NEWLINE_SEQUENCE = '\n'
+# default filters, tests and namespace
+from jinja2.filters import FILTERS as DEFAULT_FILTERS
+from jinja2.tests import TESTS as DEFAULT_TESTS
DEFAULT_NAMESPACE = {
'range': xrange,
'dict': lambda **kw: kw,
View
@@ -178,8 +178,8 @@ def __init__(self,
comment_start_string=COMMENT_START_STRING,
comment_end_string=COMMENT_END_STRING,
line_statement_prefix=LINE_STATEMENT_PREFIX,
- trim_blocks=False,
- newline_sequence='\n',
+ trim_blocks=TRIM_BLOCKS,
+ newline_sequence=NEWLINE_SEQUENCE,
extensions=(),
optimized=True,
undefined=Undefined,
@@ -442,15 +442,15 @@ class Template(object):
"""
def __new__(cls, source,
- block_start_string='{%',
- block_end_string='%}',
- variable_start_string='{{',
- variable_end_string='}}',
- comment_start_string='{#',
- comment_end_string='#}',
- line_statement_prefix=None,
- trim_blocks=False,
- newline_sequence='\n',
+ block_start_string=BLOCK_START_STRING,
+ block_end_string=BLOCK_END_STRING,
+ variable_start_string=VARIABLE_START_STRING,
+ variable_end_string=VARIABLE_END_STRING,
+ comment_start_string=COMMENT_START_STRING,
+ comment_end_string=COMMENT_END_STRING,
+ line_statement_prefix=LINE_STATEMENT_PREFIX,
+ trim_blocks=TRIM_BLOCKS,
+ newline_sequence=NEWLINE_SEQUENCE,
extensions=(),
optimized=True,
undefined=Undefined,
View
@@ -12,6 +12,7 @@
"""
from collections import deque
from jinja2 import nodes
+from jinja2.defaults import *
from jinja2.environment import get_spontaneous_environment
from jinja2.runtime import Undefined, concat
from jinja2.exceptions import TemplateAssertionError, TemplateSyntaxError
@@ -343,39 +344,35 @@ def babel_extract(fileobj, keywords, comment_tags, options):
:return: an iterator over ``(lineno, funcname, message, comments)`` tuples.
(comments will be empty currently)
"""
- encoding = options.get('encoding', 'utf-8')
-
- have_trans_extension = False
- extensions = []
+ extensions = set()
for extension in options.get('extensions', '').split(','):
extension = extension.strip()
if not extension:
continue
- extension = import_string(extension)
- if extension is InternationalizationExtension:
- have_trans_extension = True
- extensions.append(extension)
- if not have_trans_extension:
- extensions.append(InternationalizationExtension)
+ extensions.add(import_string(extension))
+ if InternationalizationExtension not in extensions:
+ extensions.add(InternationalizationExtension)
environment = get_spontaneous_environment(
- options.get('block_start_string', '{%'),
- options.get('block_end_string', '%}'),
- options.get('variable_start_string', '{{'),
- options.get('variable_end_string', '}}'),
- options.get('comment_start_string', '{#'),
- options.get('comment_end_string', '#}'),
- options.get('line_statement_prefix') or None,
- options.get('trim_blocks', '').lower() in ('1', 'on', 'yes', 'true'),
- '\n', frozenset(extensions),
+ options.get('block_start_string', BLOCK_START_STRING),
+ options.get('block_end_string', BLOCK_END_STRING),
+ options.get('variable_start_string', VARIABLE_START_STRING),
+ options.get('variable_end_string', VARIABLE_END_STRING),
+ options.get('comment_start_string', COMMENT_START_STRING),
+ options.get('comment_end_string', COMMENT_END_STRING),
+ options.get('line_statement_prefix') or LINE_STATEMENT_PREFIX,
+ str(options.get('trim_blocks', TRIM_BLOCKS)).lower() in \
+ ('1', 'on', 'yes', 'true'),
+ NEWLINE_SEQUENCE, frozenset(extensions),
# fill with defaults so that environments are shared
# with other spontaneus environments. The rest of the
# arguments are optimizer, undefined, finalize, autoescape,
# loader, cache size and auto reloading setting
True, Undefined, None, False, None, 0, False
)
- node = environment.parse(fileobj.read().decode(encoding))
+ source = fileobj.read().decode(options.get('encoding', 'utf-8'))
+ node = environment.parse(source)
for lineno, func, message in extract_from_ast(node, keywords):
yield lineno, func, message, []

0 comments on commit 4f5008f

Please sign in to comment.