From: Armin Ronacher Date: Sun, 19 May 2013 10:09:19 +0000 (+0100) Subject: Merge remote-tracking branch 'wking/keep-trailing-newline' X-Git-Tag: 2.7~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3acf0b7b37876775a6f4d8bb3b9b8469c693ba9;p=thirdparty%2Fjinja.git Merge remote-tracking branch 'wking/keep-trailing-newline' --- f3acf0b7b37876775a6f4d8bb3b9b8469c693ba9 diff --cc CHANGES index b7f28dde,43f5e8ff..c6f95bcc --- a/CHANGES +++ b/CHANGES @@@ -13,14 -13,10 +13,16 @@@ Version 2. - Added `urlencode` filter that automatically quotes values for URL safe usage with utf-8 as only supported encoding. If applications want to change this encoding they can override the filter. + - Added `keep-trailing-newline` configuration to environments and + templates to optionally preserve the final trailing newline. - Accessing `last` on the loop context no longer causes the iterator to be consumed into a list. +- Python requirement changed: 2.6, 2.7 or >= 3.3 are required now, + supported by same source code, using the "six" compatibility library. +- Allow `contextfunction` and other decorators to be applied to `__call__`. +- Added support for changing from newline to different signs in the `wordwrap` + filter. +- Added support for ignoring memcache errors silently. Version 2.6 ----------- diff --cc jinja2/environment.py index 58573a29,fb04e64c..23d00aa8 --- a/jinja2/environment.py +++ b/jinja2/environment.py @@@ -11,11 -11,7 +11,12 @@@ import os import sys from jinja2 import nodes -from jinja2.defaults import * +from jinja2.defaults import BLOCK_START_STRING, \ + BLOCK_END_STRING, VARIABLE_START_STRING, VARIABLE_END_STRING, \ + COMMENT_START_STRING, COMMENT_END_STRING, LINE_STATEMENT_PREFIX, \ + LINE_COMMENT_PREFIX, TRIM_BLOCKS, NEWLINE_SEQUENCE, \ - DEFAULT_FILTERS, DEFAULT_TESTS, DEFAULT_NAMESPACE ++ DEFAULT_FILTERS, DEFAULT_TESTS, DEFAULT_NAMESPACE, \ ++ KEEP_TRAILING_NEWLINE from jinja2.lexer import get_lexer, TokenStream from jinja2.parser import Parser from jinja2.optimizer import optimize diff --cc jinja2/lexer.py index bd2e8616,0eb19f74..5594e0a6 --- a/jinja2/lexer.py +++ b/jinja2/lexer.py @@@ -557,7 -551,14 +559,14 @@@ class Lexer(object) """This method tokenizes the text and returns the tokens in a generator. Use this method if you just want to tokenize a template. """ - source = '\n'.join(six.text_type(source).splitlines()) - source = unicode(source) ++ source = six.text_type(source) + lines = source.splitlines() + if self.keep_trailing_newline and source: + for newline in ('\r\n', '\r', '\n'): + if source.endswith(newline): + lines.append('') + break + source = '\n'.join(lines) pos = 0 lineno = 1 stack = ['root']