moved environment defaults to jinja2.defaults
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent f3c35c4 · Browse files · 3 files·+34 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+34 added−33 removed
- other:+34 added−33 removed
Provenance
- Commit
4f5008f- Tree
13906a6- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
f3c35c4
3 files changed+34 added−33 removed
modified:jinja2/defaults.py+6 added-2 removed
6 unmodified lines7 8 :copyright: 2007-2008 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11-from jinja2.filters import FILTERS as DEFAULT_FILTERS12-from jinja2.tests import TESTS as DEFAULT_TESTS11 from jinja2.utils import generate_lorem_ipsum12 13 14+# defaults for the parser / lexer15 BLOCK_START_STRING = '{%'16 BLOCK_END_STRING = '%}'17 VARIABLE_START_STRING = '{{'18 VARIABLE_END_STRING = '}}'19 COMMENT_START_STRING = '{#'20 COMMENT_END_STRING = '#}'21 LINE_STATEMENT_PREFIX = None22+TRIM_BLOCKS = False23+NEWLINE_SEQUENCE = '\n'24 25 26+# default filters, tests and namespace27+from jinja2.filters import FILTERS as DEFAULT_FILTERS28+from jinja2.tests import TESTS as DEFAULT_TESTS29 DEFAULT_NAMESPACE = {30 'range': xrange,31 'dict': lambda **kw: kw,32 'lipsum': generate_lorem_ipsum5 unmodified linesmodified:jinja2/environment.py+11 added-11 removed
176 unmodified lines177 variable_end_string=VARIABLE_END_STRING,178 comment_start_string=COMMENT_START_STRING,179 comment_end_string=COMMENT_END_STRING,180 line_statement_prefix=LINE_STATEMENT_PREFIX,181- trim_blocks=False,182- newline_sequence='\n',181+ trim_blocks=TRIM_BLOCKS,182+ newline_sequence=NEWLINE_SEQUENCE,183 extensions=(),184 optimized=True,185 undefined=Undefined,186 finalize=None,254 unmodified lines441 StopIteration442 """443 444 def __new__(cls, source,445- block_start_string='{%',446- block_end_string='%}',447- variable_start_string='{{',448- variable_end_string='}}',449- comment_start_string='{#',450- comment_end_string='#}',451- line_statement_prefix=None,452- trim_blocks=False,453- newline_sequence='\n',445+ block_start_string=BLOCK_START_STRING,446+ block_end_string=BLOCK_END_STRING,447+ variable_start_string=VARIABLE_START_STRING,448+ variable_end_string=VARIABLE_END_STRING,449+ comment_start_string=COMMENT_START_STRING,450+ comment_end_string=COMMENT_END_STRING,451+ line_statement_prefix=LINE_STATEMENT_PREFIX,452+ trim_blocks=TRIM_BLOCKS,453+ newline_sequence=NEWLINE_SEQUENCE,454 extensions=(),455 optimized=True,456 undefined=Undefined,457 finalize=None,233 unmodified linesmodified:jinja2/ext.py+17 added-20 removed
10 unmodified lines11 :license: BSD.12 """13 from collections import deque14 from jinja2 import nodes15+from jinja2.defaults import *16 from jinja2.environment import get_spontaneous_environment17 from jinja2.runtime import Undefined, concat18 from jinja2.exceptions import TemplateAssertionError, TemplateSyntaxError19 from jinja2.utils import contextfunction, import_string, Markup323 unmodified lines343 :param options: a dictionary of additional options (optional)344 :return: an iterator over ``(lineno, funcname, message, comments)`` tuples.345 (comments will be empty currently)346 """346- encoding = options.get('encoding', 'utf-8')347-348- have_trans_extension = False349- extensions = []347+ extensions = set()348 for extension in options.get('extensions', '').split(','):349 extension = extension.strip()350 if not extension:351 continue354- extension = import_string(extension)355- if extension is InternationalizationExtension:356- have_trans_extension = True357- extensions.append(extension)358- if not have_trans_extension:359- extensions.append(InternationalizationExtension)352+ extensions.add(import_string(extension))353+ if InternationalizationExtension not in extensions:354+ extensions.add(InternationalizationExtension)355 356 environment = get_spontaneous_environment(362- options.get('block_start_string', '{%'),363- options.get('block_end_string', '%}'),364- options.get('variable_start_string', '{{'),365- options.get('variable_end_string', '}}'),366- options.get('comment_start_string', '{#'),367- options.get('comment_end_string', '#}'),368- options.get('line_statement_prefix') or None,369- options.get('trim_blocks', '').lower() in ('1', 'on', 'yes', 'true'),370- '\n', frozenset(extensions),357+ options.get('block_start_string', BLOCK_START_STRING),358+ options.get('block_end_string', BLOCK_END_STRING),359+ options.get('variable_start_string', VARIABLE_START_STRING),360+ options.get('variable_end_string', VARIABLE_END_STRING),361+ options.get('comment_start_string', COMMENT_START_STRING),362+ options.get('comment_end_string', COMMENT_END_STRING),363+ options.get('line_statement_prefix') or LINE_STATEMENT_PREFIX,364+ str(options.get('trim_blocks', TRIM_BLOCKS)).lower() in \365+ ('1', 'on', 'yes', 'true'),366+ NEWLINE_SEQUENCE, frozenset(extensions),367 # fill with defaults so that environments are shared368 # with other spontaneus environments. The rest of the369 # arguments are optimizer, undefined, finalize, autoescape,370 # loader, cache size and auto reloading setting371 True, Undefined, None, False, None, 0, False372 )373 378- node = environment.parse(fileobj.read().decode(encoding))374+ source = fileobj.read().decode(options.get('encoding', 'utf-8'))375+ node = environment.parse(source)376 for lineno, func, message in extract_from_ast(node, keywords):377 yield lineno, func, message, []378 379 4 unmodified lines