Skip to content
Myr

Environment.lex returns unicode tokens now, even if the input data was a bytestring.

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 6df604e · Browse files · 3 files+10 added−5 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+10 added−5 removed

  • other:+10 added−5 removed

3 files+10 added−5 removed

modified:jinja2/ext.py+7 added-2 removed
23 unmodified lines
24GETTEXT_FUNCTIONS = ('_', 'gettext', 'ngettext')252627class ExtensionRegistry(type):28 """Gives the extension a unique identifier."""28 """Gives the extension an unique identifier."""2930 def __new__(cls, name, bases, d):31 rv = type.__new__(cls, name, bases, d)32 rv.identifier = rv.__module__ + '.' + rv.__name__
61 unmodified lines
94 return nodes.Call(self.attr(name, lineno=lineno), args, kwargs,95 dyn_args, dyn_kwargs, lineno=lineno)969798@contextfunction99def _gettext_alias(context, string):100 return context.resolve('gettext')(string)101102103class InternationalizationExtension(Extension):104 """This extension adds gettext support to Jinja2."""105 tags = set(['trans'])106107 def __init__(self, environment):108 Extension.__init__(self, environment)104 environment.globals['_'] = contextfunction(lambda c, x: c['gettext'](x))109 environment.globals['_'] = _gettext_alias110 environment.extend(111 install_gettext_translations=self._install,112 install_null_translations=self._install_null,113 uninstall_gettext_translations=self._uninstall,
273 unmodified lines
modified:jinja2/lexer.py+1 added-2 removed
369 unmodified lines
370 a generator or token tuples. Additionally all token values are already371 converted into types and postprocessed. For example comments are removed,372 integers and floats converted, strings unescaped etc.373 """374 source = unicode(source)374 def generate():375 for lineno, token, value in self.tokeniter(source, name, filename):376 if token in ('comment_begin', 'comment', 'comment_end',377 'whitespace'):
45 unmodified lines
423 The output you get is not compatible with the input the jinja parser424 wants. The parser uses the `tokenize` function with returns a425 `TokenStream` and postprocessed tokens.426 """428 source = '\n'.join(source.splitlines())427 source = u'\n'.join(unicode(source).splitlines())428 pos = 0429 lineno = 1430 stack = ['root']431 statetokens = self.rules['root']
119 unmodified lines
modified:jinja2-debug.py+2 added-1 removed
11 unmodified lines
12import sys13import jinja214from werkzeug import script1516env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do'])16env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do',17 'jinja2.ext.loopcontrols'])1819def shell_init_func():20 def _compile(x):21 print env.compile(x, raw=True)
19 unmodified lines