mirror of
https://gitee.com/openharmony/third_party_jinja2
synced 2024-11-27 09:20:49 +00:00
parent
4ec93a454b
commit
4a59ac9514
21
CHANGES.rst
21
CHANGES.rst
@ -20,7 +20,7 @@ Unreleased
|
|||||||
- Fix a bug causing deadlocks in ``LRUCache.setdefault``. :pr:`1000`
|
- Fix a bug causing deadlocks in ``LRUCache.setdefault``. :pr:`1000`
|
||||||
- The ``trim`` filter takes an optional string of characters to trim.
|
- The ``trim`` filter takes an optional string of characters to trim.
|
||||||
:pr:`828`
|
:pr:`828`
|
||||||
- A new ``jinja.ext.debug`` extension adds a ``{% debug %}`` tag to
|
- A new ``jinja2.ext.debug`` extension adds a ``{% debug %}`` tag to
|
||||||
quickly dump the current context and available filters and tests.
|
quickly dump the current context and available filters and tests.
|
||||||
:issue:`174`, :pr:`798, 983`
|
:issue:`174`, :pr:`798, 983`
|
||||||
- Lexing templates with large amounts of whitespace is much faster.
|
- Lexing templates with large amounts of whitespace is much faster.
|
||||||
@ -364,9 +364,11 @@ Released 2015-07-26, codename Replacement
|
|||||||
arguments. This change makes ``{% macro m(x, y=1, z) %}`` a syntax
|
arguments. This change makes ``{% macro m(x, y=1, z) %}`` a syntax
|
||||||
error. The previous behavior for this code was broken anyway
|
error. The previous behavior for this code was broken anyway
|
||||||
(resulting in the default value being applied to ``y``).
|
(resulting in the default value being applied to ``y``).
|
||||||
- Add ability to use custom subclasses of ``CodeGenerator`` and
|
- Add ability to use custom subclasses of
|
||||||
``Context`` by adding two new attributes to the environment
|
``jinja2.compiler.CodeGenerator`` and ``jinja2.runtime.Context`` by
|
||||||
(``code_generator_class`` and ``context_class``). :pr:`404`
|
adding two new attributes to the environment
|
||||||
|
(``code_generator_class`` and ``context_class``) (pull request
|
||||||
|
``:issue:`404```).
|
||||||
- Added support for context/environment/evalctx decorator functions on
|
- Added support for context/environment/evalctx decorator functions on
|
||||||
the finalize callback of the environment.
|
the finalize callback of the environment.
|
||||||
- Escape query strings for urlencode properly. Previously slashes were
|
- Escape query strings for urlencode properly. Previously slashes were
|
||||||
@ -557,6 +559,7 @@ Released 2010-05-29, codename Incoherence
|
|||||||
- Fixed a bug for getattribute constant folding.
|
- Fixed a bug for getattribute constant folding.
|
||||||
- Support for newstyle gettext translations which result in a nicer
|
- Support for newstyle gettext translations which result in a nicer
|
||||||
in-template user interface and more consistent catalogs.
|
in-template user interface and more consistent catalogs.
|
||||||
|
(:ref:`newstyle-gettext`)
|
||||||
- It's now possible to register extensions after an environment was
|
- It's now possible to register extensions after an environment was
|
||||||
created.
|
created.
|
||||||
|
|
||||||
@ -584,7 +587,7 @@ Released 2010-04-13, codename Correlation
|
|||||||
folder.
|
folder.
|
||||||
- The _speedups C extension now supports Python 3.
|
- The _speedups C extension now supports Python 3.
|
||||||
- Added support for autoescaping toggling sections and support for
|
- Added support for autoescaping toggling sections and support for
|
||||||
evaluation contexts.
|
evaluation contexts (:ref:`eval-context`).
|
||||||
- Extensions have a priority now.
|
- Extensions have a priority now.
|
||||||
|
|
||||||
|
|
||||||
@ -686,7 +689,7 @@ Released 2008-11-23, codename Yasuzō
|
|||||||
- Added ``sort`` filter that works like ``dictsort`` but for arbitrary
|
- Added ``sort`` filter that works like ``dictsort`` but for arbitrary
|
||||||
sequences.
|
sequences.
|
||||||
- Fixed a bug with empty statements in macros.
|
- Fixed a bug with empty statements in macros.
|
||||||
- Implemented a bytecode cache system.
|
- Implemented a bytecode cache system. (:ref:`bytecode-cache`)
|
||||||
- The template context is now weakref-able
|
- The template context is now weakref-able
|
||||||
- Inclusions and imports "with context" forward all variables now, not
|
- Inclusions and imports "with context" forward all variables now, not
|
||||||
only the initial context.
|
only the initial context.
|
||||||
@ -706,11 +709,13 @@ Released 2008-07-17, codename Jinjavitus
|
|||||||
from slightly. It's now possible to give attributes or items a
|
from slightly. It's now possible to give attributes or items a
|
||||||
higher priority by either using dot-notation lookup or the bracket
|
higher priority by either using dot-notation lookup or the bracket
|
||||||
syntax. This also changed the AST slightly. ``Subscript`` is gone
|
syntax. This also changed the AST slightly. ``Subscript`` is gone
|
||||||
and was replaced with ``Getitem`` and ``Getattr``.
|
and was replaced with :class:`~jinja2.nodes.Getitem` and
|
||||||
|
:class:`~jinja2.nodes.Getattr`. For more information see :ref:`the
|
||||||
|
implementation details <notes-on-subscriptions>`.
|
||||||
- Added support for preprocessing and token stream filtering for
|
- Added support for preprocessing and token stream filtering for
|
||||||
extensions. This would allow extensions to allow simplified gettext
|
extensions. This would allow extensions to allow simplified gettext
|
||||||
calls in template data and something similar.
|
calls in template data and something similar.
|
||||||
- Added ``TemplateStream.dump``.
|
- Added :meth:`jinja2.environment.TemplateStream.dump`.
|
||||||
- Added missing support for implicit string literal concatenation.
|
- Added missing support for implicit string literal concatenation.
|
||||||
``{{ "foo" "bar" }}`` is equivalent to ``{{ "foobar" }}``
|
``{{ "foo" "bar" }}`` is equivalent to ``{{ "foobar" }}``
|
||||||
- ``else`` is optional for conditional expressions. If not given it
|
- ``else`` is optional for conditional expressions. If not given it
|
||||||
|
@ -33,7 +33,7 @@ Install and update using `pip`_:
|
|||||||
|
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
$ pip install -U Jinja
|
$ pip install -U Jinja2
|
||||||
|
|
||||||
.. _pip: https://pip.pypa.io/en/stable/quickstart/
|
.. _pip: https://pip.pypa.io/en/stable/quickstart/
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ Links
|
|||||||
|
|
||||||
- Website: https://palletsprojects.com/p/jinja/
|
- Website: https://palletsprojects.com/p/jinja/
|
||||||
- Documentation: https://jinja.palletsprojects.com/
|
- Documentation: https://jinja.palletsprojects.com/
|
||||||
- Releases: https://pypi.org/project/Jinja/
|
- Releases: https://pypi.org/project/Jinja2/
|
||||||
- Code: https://github.com/pallets/jinja
|
- Code: https://github.com/pallets/jinja
|
||||||
- Issue tracker: https://github.com/pallets/jinja/issues
|
- Issue tracker: https://github.com/pallets/jinja/issues
|
||||||
- Test status: https://dev.azure.com/pallets/jinja/_build
|
- Test status: https://dev.azure.com/pallets/jinja/_build
|
||||||
|
96
docs/api.rst
96
docs/api.rst
@ -1,7 +1,7 @@
|
|||||||
API
|
API
|
||||||
===
|
===
|
||||||
|
|
||||||
.. module:: jinja
|
.. module:: jinja2
|
||||||
:noindex:
|
:noindex:
|
||||||
:synopsis: public Jinja API
|
:synopsis: public Jinja API
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ are in use.
|
|||||||
The simplest way to configure Jinja to load templates for your application
|
The simplest way to configure Jinja to load templates for your application
|
||||||
looks roughly like this::
|
looks roughly like this::
|
||||||
|
|
||||||
from jinja import Environment, PackageLoader, select_autoescape
|
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||||
env = Environment(
|
env = Environment(
|
||||||
loader=PackageLoader('yourapplication', 'templates'),
|
loader=PackageLoader('yourapplication', 'templates'),
|
||||||
autoescape=select_autoescape(['html', 'xml'])
|
autoescape=select_autoescape(['html', 'xml'])
|
||||||
@ -142,7 +142,7 @@ useful if you want to dig deeper into Jinja or :ref:`develop extensions
|
|||||||
|
|
||||||
If the environment is sandboxed this attribute is `True`. For the
|
If the environment is sandboxed this attribute is `True`. For the
|
||||||
sandbox mode have a look at the documentation for the
|
sandbox mode have a look at the documentation for the
|
||||||
:class:`~jinja.sandbox.SandboxedEnvironment`.
|
:class:`~jinja2.sandbox.SandboxedEnvironment`.
|
||||||
|
|
||||||
.. attribute:: filters
|
.. attribute:: filters
|
||||||
|
|
||||||
@ -182,7 +182,7 @@ useful if you want to dig deeper into Jinja or :ref:`develop extensions
|
|||||||
The context used for templates. This should not be changed
|
The context used for templates. This should not be changed
|
||||||
in most cases, unless you need to modify internals of how
|
in most cases, unless you need to modify internals of how
|
||||||
template variables are handled. For details, see
|
template variables are handled. For details, see
|
||||||
:class:`~jinja.runtime.Context`.
|
:class:`~jinja2.runtime.Context`.
|
||||||
|
|
||||||
.. automethod:: overlay([options])
|
.. automethod:: overlay([options])
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ useful if you want to dig deeper into Jinja or :ref:`develop extensions
|
|||||||
.. automethod:: generate_async([context])
|
.. automethod:: generate_async([context])
|
||||||
|
|
||||||
|
|
||||||
.. autoclass:: jinja.environment.TemplateStream()
|
.. autoclass:: jinja2.environment.TemplateStream()
|
||||||
:members: disable_buffering, enable_buffering, dump
|
:members: disable_buffering, enable_buffering, dump
|
||||||
|
|
||||||
|
|
||||||
@ -267,14 +267,14 @@ future. It's recommended to configure a sensible default for
|
|||||||
autoescaping. This makes it possible to enable and disable autoescaping
|
autoescaping. This makes it possible to enable and disable autoescaping
|
||||||
on a per-template basis (HTML versus text for instance).
|
on a per-template basis (HTML versus text for instance).
|
||||||
|
|
||||||
.. autofunction:: jinja.select_autoescape
|
.. autofunction:: jinja2.select_autoescape
|
||||||
|
|
||||||
Here a recommended setup that enables autoescaping for templates ending
|
Here a recommended setup that enables autoescaping for templates ending
|
||||||
in ``'.html'``, ``'.htm'`` and ``'.xml'`` and disabling it by default
|
in ``'.html'``, ``'.htm'`` and ``'.xml'`` and disabling it by default
|
||||||
for all other extensions. You can use the :func:`~jinja.select_autoescape`
|
for all other extensions. You can use the :func:`~jinja2.select_autoescape`
|
||||||
function for this::
|
function for this::
|
||||||
|
|
||||||
from jinja import Environment, select_autoescape
|
from jinja2 import Environment, select_autoescape
|
||||||
env = Environment(autoescape=select_autoescape(['html', 'htm', 'xml']),
|
env = Environment(autoescape=select_autoescape(['html', 'htm', 'xml']),
|
||||||
loader=PackageLoader('mypackage'))
|
loader=PackageLoader('mypackage'))
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ others fail.
|
|||||||
The closest to regular Python behavior is the :class:`StrictUndefined` which
|
The closest to regular Python behavior is the :class:`StrictUndefined` which
|
||||||
disallows all operations beside testing if it's an undefined object.
|
disallows all operations beside testing if it's an undefined object.
|
||||||
|
|
||||||
.. autoclass:: jinja.Undefined()
|
.. autoclass:: jinja2.Undefined()
|
||||||
|
|
||||||
.. attribute:: _undefined_hint
|
.. attribute:: _undefined_hint
|
||||||
|
|
||||||
@ -352,16 +352,16 @@ disallows all operations beside testing if it's an undefined object.
|
|||||||
:attr:`_undefined_exception` with an error message generated
|
:attr:`_undefined_exception` with an error message generated
|
||||||
from the undefined hints stored on the undefined object.
|
from the undefined hints stored on the undefined object.
|
||||||
|
|
||||||
.. autoclass:: jinja.ChainableUndefined()
|
.. autoclass:: jinja2.ChainableUndefined()
|
||||||
|
|
||||||
.. autoclass:: jinja.DebugUndefined()
|
.. autoclass:: jinja2.DebugUndefined()
|
||||||
|
|
||||||
.. autoclass:: jinja.StrictUndefined()
|
.. autoclass:: jinja2.StrictUndefined()
|
||||||
|
|
||||||
There is also a factory function that can decorate undefined objects to
|
There is also a factory function that can decorate undefined objects to
|
||||||
implement logging on failures:
|
implement logging on failures:
|
||||||
|
|
||||||
.. autofunction:: jinja.make_logging_undefined
|
.. autofunction:: jinja2.make_logging_undefined
|
||||||
|
|
||||||
Undefined objects are created by calling :attr:`undefined`.
|
Undefined objects are created by calling :attr:`undefined`.
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ Undefined objects are created by calling :attr:`undefined`.
|
|||||||
The Context
|
The Context
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
.. autoclass:: jinja.runtime.Context()
|
.. autoclass:: jinja2.runtime.Context()
|
||||||
:members: resolve, get_exported, get_all
|
:members: resolve, get_exported, get_all
|
||||||
|
|
||||||
.. attribute:: parent
|
.. attribute:: parent
|
||||||
@ -437,7 +437,7 @@ The Context
|
|||||||
|
|
||||||
The current :ref:`eval-context`.
|
The current :ref:`eval-context`.
|
||||||
|
|
||||||
.. automethod:: jinja.runtime.Context.call(callable, \*args, \**kwargs)
|
.. automethod:: jinja2.runtime.Context.call(callable, \*args, \**kwargs)
|
||||||
|
|
||||||
|
|
||||||
.. admonition:: Implementation
|
.. admonition:: Implementation
|
||||||
@ -464,24 +464,24 @@ size by default and templates are automatically reloaded.
|
|||||||
All loaders are subclasses of :class:`BaseLoader`. If you want to create your
|
All loaders are subclasses of :class:`BaseLoader`. If you want to create your
|
||||||
own loader, subclass :class:`BaseLoader` and override `get_source`.
|
own loader, subclass :class:`BaseLoader` and override `get_source`.
|
||||||
|
|
||||||
.. autoclass:: jinja.BaseLoader
|
.. autoclass:: jinja2.BaseLoader
|
||||||
:members: get_source, load
|
:members: get_source, load
|
||||||
|
|
||||||
Here a list of the builtin loaders Jinja provides:
|
Here a list of the builtin loaders Jinja provides:
|
||||||
|
|
||||||
.. autoclass:: jinja.FileSystemLoader
|
.. autoclass:: jinja2.FileSystemLoader
|
||||||
|
|
||||||
.. autoclass:: jinja.PackageLoader
|
.. autoclass:: jinja2.PackageLoader
|
||||||
|
|
||||||
.. autoclass:: jinja.DictLoader
|
.. autoclass:: jinja2.DictLoader
|
||||||
|
|
||||||
.. autoclass:: jinja.FunctionLoader
|
.. autoclass:: jinja2.FunctionLoader
|
||||||
|
|
||||||
.. autoclass:: jinja.PrefixLoader
|
.. autoclass:: jinja2.PrefixLoader
|
||||||
|
|
||||||
.. autoclass:: jinja.ChoiceLoader
|
.. autoclass:: jinja2.ChoiceLoader
|
||||||
|
|
||||||
.. autoclass:: jinja.ModuleLoader
|
.. autoclass:: jinja2.ModuleLoader
|
||||||
|
|
||||||
|
|
||||||
.. _bytecode-cache:
|
.. _bytecode-cache:
|
||||||
@ -499,10 +499,10 @@ the application.
|
|||||||
|
|
||||||
To use a bytecode cache, instantiate it and pass it to the :class:`Environment`.
|
To use a bytecode cache, instantiate it and pass it to the :class:`Environment`.
|
||||||
|
|
||||||
.. autoclass:: jinja.BytecodeCache
|
.. autoclass:: jinja2.BytecodeCache
|
||||||
:members: load_bytecode, dump_bytecode, clear
|
:members: load_bytecode, dump_bytecode, clear
|
||||||
|
|
||||||
.. autoclass:: jinja.bccache.Bucket
|
.. autoclass:: jinja2.bccache.Bucket
|
||||||
:members: write_bytecode, load_bytecode, bytecode_from_string,
|
:members: write_bytecode, load_bytecode, bytecode_from_string,
|
||||||
bytecode_to_string, reset
|
bytecode_to_string, reset
|
||||||
|
|
||||||
@ -521,9 +521,9 @@ To use a bytecode cache, instantiate it and pass it to the :class:`Environment`.
|
|||||||
|
|
||||||
Builtin bytecode caches:
|
Builtin bytecode caches:
|
||||||
|
|
||||||
.. autoclass:: jinja.FileSystemBytecodeCache
|
.. autoclass:: jinja2.FileSystemBytecodeCache
|
||||||
|
|
||||||
.. autoclass:: jinja.MemcachedBytecodeCache
|
.. autoclass:: jinja2.MemcachedBytecodeCache
|
||||||
|
|
||||||
|
|
||||||
Async Support
|
Async Support
|
||||||
@ -569,7 +569,7 @@ Policies
|
|||||||
Starting with Jinja 2.9 policies can be configured on the environment
|
Starting with Jinja 2.9 policies can be configured on the environment
|
||||||
which can slightly influence how filters and other template constructs
|
which can slightly influence how filters and other template constructs
|
||||||
behave. They can be configured with the
|
behave. They can be configured with the
|
||||||
:attr:`~jinja.Environment.policies` attribute.
|
:attr:`~jinja2.Environment.policies` attribute.
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
@ -626,17 +626,17 @@ Utilities
|
|||||||
These helper functions and classes are useful if you add custom filters or
|
These helper functions and classes are useful if you add custom filters or
|
||||||
functions to a Jinja environment.
|
functions to a Jinja environment.
|
||||||
|
|
||||||
.. autofunction:: jinja.environmentfilter
|
.. autofunction:: jinja2.environmentfilter
|
||||||
|
|
||||||
.. autofunction:: jinja.contextfilter
|
.. autofunction:: jinja2.contextfilter
|
||||||
|
|
||||||
.. autofunction:: jinja.evalcontextfilter
|
.. autofunction:: jinja2.evalcontextfilter
|
||||||
|
|
||||||
.. autofunction:: jinja.environmentfunction
|
.. autofunction:: jinja2.environmentfunction
|
||||||
|
|
||||||
.. autofunction:: jinja.contextfunction
|
.. autofunction:: jinja2.contextfunction
|
||||||
|
|
||||||
.. autofunction:: jinja.evalcontextfunction
|
.. autofunction:: jinja2.evalcontextfunction
|
||||||
|
|
||||||
.. function:: escape(s)
|
.. function:: escape(s)
|
||||||
|
|
||||||
@ -647,11 +647,11 @@ functions to a Jinja environment.
|
|||||||
|
|
||||||
The return value is a :class:`Markup` string.
|
The return value is a :class:`Markup` string.
|
||||||
|
|
||||||
.. autofunction:: jinja.clear_caches
|
.. autofunction:: jinja2.clear_caches
|
||||||
|
|
||||||
.. autofunction:: jinja.is_undefined
|
.. autofunction:: jinja2.is_undefined
|
||||||
|
|
||||||
.. autoclass:: jinja.Markup([string])
|
.. autoclass:: jinja2.Markup([string])
|
||||||
:members: escape, unescape, striptags
|
:members: escape, unescape, striptags
|
||||||
|
|
||||||
.. admonition:: Note
|
.. admonition:: Note
|
||||||
@ -664,15 +664,15 @@ functions to a Jinja environment.
|
|||||||
Exceptions
|
Exceptions
|
||||||
----------
|
----------
|
||||||
|
|
||||||
.. autoexception:: jinja.TemplateError
|
.. autoexception:: jinja2.TemplateError
|
||||||
|
|
||||||
.. autoexception:: jinja.UndefinedError
|
.. autoexception:: jinja2.UndefinedError
|
||||||
|
|
||||||
.. autoexception:: jinja.TemplateNotFound
|
.. autoexception:: jinja2.TemplateNotFound
|
||||||
|
|
||||||
.. autoexception:: jinja.TemplatesNotFound
|
.. autoexception:: jinja2.TemplatesNotFound
|
||||||
|
|
||||||
.. autoexception:: jinja.TemplateSyntaxError
|
.. autoexception:: jinja2.TemplateSyntaxError
|
||||||
|
|
||||||
.. attribute:: message
|
.. attribute:: message
|
||||||
|
|
||||||
@ -695,9 +695,9 @@ Exceptions
|
|||||||
unicode strings is that Python 2.x is not using unicode for exceptions
|
unicode strings is that Python 2.x is not using unicode for exceptions
|
||||||
and tracebacks as well as the compiler. This will change with Python 3.
|
and tracebacks as well as the compiler. This will change with Python 3.
|
||||||
|
|
||||||
.. autoexception:: jinja.TemplateRuntimeError
|
.. autoexception:: jinja2.TemplateRuntimeError
|
||||||
|
|
||||||
.. autoexception:: jinja.TemplateAssertionError
|
.. autoexception:: jinja2.TemplateAssertionError
|
||||||
|
|
||||||
|
|
||||||
.. _writing-filters:
|
.. _writing-filters:
|
||||||
@ -739,7 +739,7 @@ paragraphs and marks the return value as safe HTML string if autoescaping is
|
|||||||
enabled::
|
enabled::
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from jinja import evalcontextfilter, Markup, escape
|
from jinja2 import evalcontextfilter, Markup, escape
|
||||||
|
|
||||||
_paragraph_re = re.compile(r'(?:\r\n|\r(?!\n)|\n){2,}')
|
_paragraph_re = re.compile(r'(?:\r\n|\r(?!\n)|\n){2,}')
|
||||||
|
|
||||||
@ -805,7 +805,7 @@ must only happen with a :class:`nodes.EvalContextModifier` and
|
|||||||
:class:`nodes.ScopedEvalContextModifier` from an extension, not on the
|
:class:`nodes.ScopedEvalContextModifier` from an extension, not on the
|
||||||
eval context object itself.
|
eval context object itself.
|
||||||
|
|
||||||
.. autoclass:: jinja.nodes.EvalContext
|
.. autoclass:: jinja2.nodes.EvalContext
|
||||||
|
|
||||||
.. attribute:: autoescape
|
.. attribute:: autoescape
|
||||||
|
|
||||||
@ -928,6 +928,6 @@ could help applications to implement more advanced template concepts. All
|
|||||||
the functions of the meta API operate on an abstract syntax tree as
|
the functions of the meta API operate on an abstract syntax tree as
|
||||||
returned by the :meth:`Environment.parse` method.
|
returned by the :meth:`Environment.parse` method.
|
||||||
|
|
||||||
.. autofunction:: jinja.meta.find_undeclared_variables
|
.. autofunction:: jinja2.meta.find_undeclared_variables
|
||||||
|
|
||||||
.. autofunction:: jinja.meta.find_referenced_templates
|
.. autofunction:: jinja2.meta.find_referenced_templates
|
||||||
|
@ -6,7 +6,7 @@ from pallets_sphinx_themes import ProjectLink
|
|||||||
project = "Jinja"
|
project = "Jinja"
|
||||||
copyright = "2007 Pallets"
|
copyright = "2007 Pallets"
|
||||||
author = "Pallets"
|
author = "Pallets"
|
||||||
release, version = get_version("Jinja")
|
release, version = get_version("Jinja2")
|
||||||
|
|
||||||
# General --------------------------------------------------------------
|
# General --------------------------------------------------------------
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ html_context = {
|
|||||||
"project_links": [
|
"project_links": [
|
||||||
ProjectLink("Donate to Pallets", "https://palletsprojects.com/donate"),
|
ProjectLink("Donate to Pallets", "https://palletsprojects.com/donate"),
|
||||||
ProjectLink("Jinja Website", "https://palletsprojects.com/p/jinja/"),
|
ProjectLink("Jinja Website", "https://palletsprojects.com/p/jinja/"),
|
||||||
ProjectLink("PyPI releases", "https://pypi.org/project/Jinja/"),
|
ProjectLink("PyPI releases", "https://pypi.org/project/Jinja2/"),
|
||||||
ProjectLink("Source Code", "https://github.com/pallets/jinja/"),
|
ProjectLink("Source Code", "https://github.com/pallets/jinja/"),
|
||||||
ProjectLink("Issue Tracker", "https://github.com/pallets/jinja/issues/"),
|
ProjectLink("Issue Tracker", "https://github.com/pallets/jinja/issues/"),
|
||||||
]
|
]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from jinja import nodes
|
from jinja2 import nodes
|
||||||
from jinja.ext import Extension
|
from jinja2.ext import Extension
|
||||||
|
|
||||||
|
|
||||||
class FragmentCacheExtension(Extension):
|
class FragmentCacheExtension(Extension):
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from jinja.exceptions import TemplateSyntaxError
|
from jinja2.exceptions import TemplateSyntaxError
|
||||||
from jinja.ext import Extension
|
from jinja2.ext import Extension
|
||||||
from jinja.lexer import count_newlines
|
from jinja2.lexer import count_newlines
|
||||||
from jinja.lexer import Token
|
from jinja2.lexer import Token
|
||||||
|
|
||||||
|
|
||||||
_outside_re = re.compile(r"\\?(gettext|_)\(")
|
_outside_re = re.compile(r"\\?(gettext|_)\(")
|
||||||
|
@ -14,10 +14,10 @@ Adding Extensions
|
|||||||
Extensions are added to the Jinja environment at creation time. Once the
|
Extensions are added to the Jinja environment at creation time. Once the
|
||||||
environment is created additional extensions cannot be added. To add an
|
environment is created additional extensions cannot be added. To add an
|
||||||
extension pass a list of extension classes or import paths to the
|
extension pass a list of extension classes or import paths to the
|
||||||
``extensions`` parameter of the :class:`~jinja.Environment` constructor. The following
|
``extensions`` parameter of the :class:`~jinja2.Environment` constructor. The following
|
||||||
example creates a Jinja environment with the i18n extension loaded::
|
example creates a Jinja environment with the i18n extension loaded::
|
||||||
|
|
||||||
jinja_env = Environment(extensions=['jinja.ext.i18n'])
|
jinja_env = Environment(extensions=['jinja2.ext.i18n'])
|
||||||
|
|
||||||
|
|
||||||
.. _i18n-extension:
|
.. _i18n-extension:
|
||||||
@ -25,7 +25,7 @@ example creates a Jinja environment with the i18n extension loaded::
|
|||||||
i18n Extension
|
i18n Extension
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
**Import name:** ``jinja.ext.i18n``
|
**Import name:** ``jinja2.ext.i18n``
|
||||||
|
|
||||||
The i18n extension can be used in combination with `gettext`_ or
|
The i18n extension can be used in combination with `gettext`_ or
|
||||||
`Babel`_. When it's enabled, Jinja provides a ``trans`` statement that
|
`Babel`_. When it's enabled, Jinja provides a ``trans`` statement that
|
||||||
@ -41,7 +41,7 @@ Environment Methods
|
|||||||
After enabling the extension, the environment provides the following
|
After enabling the extension, the environment provides the following
|
||||||
additional methods:
|
additional methods:
|
||||||
|
|
||||||
.. method:: jinja.Environment.install_gettext_translations(translations, newstyle=False)
|
.. method:: jinja2.Environment.install_gettext_translations(translations, newstyle=False)
|
||||||
|
|
||||||
Installs a translation globally for the environment. The
|
Installs a translation globally for the environment. The
|
||||||
``translations`` object must implement ``gettext`` and ``ngettext``
|
``translations`` object must implement ``gettext`` and ``ngettext``
|
||||||
@ -51,7 +51,7 @@ additional methods:
|
|||||||
|
|
||||||
.. versionchanged:: 2.5 Added new-style gettext support.
|
.. versionchanged:: 2.5 Added new-style gettext support.
|
||||||
|
|
||||||
.. method:: jinja.Environment.install_null_translations(newstyle=False)
|
.. method:: jinja2.Environment.install_null_translations(newstyle=False)
|
||||||
|
|
||||||
Install no-op gettext functions. This is useful if you want to
|
Install no-op gettext functions. This is useful if you want to
|
||||||
prepare the application for internationalization but don't want to
|
prepare the application for internationalization but don't want to
|
||||||
@ -59,7 +59,7 @@ additional methods:
|
|||||||
|
|
||||||
.. versionchanged:: 2.5 Added new-style gettext support.
|
.. versionchanged:: 2.5 Added new-style gettext support.
|
||||||
|
|
||||||
.. method:: jinja.Environment.install_gettext_callables(gettext, ngettext, newstyle=False)
|
.. method:: jinja2.Environment.install_gettext_callables(gettext, ngettext, newstyle=False)
|
||||||
|
|
||||||
Install the given ``gettext`` and ``ngettext`` callables into the
|
Install the given ``gettext`` and ``ngettext`` callables into the
|
||||||
environment. They should behave exactly like
|
environment. They should behave exactly like
|
||||||
@ -71,11 +71,11 @@ additional methods:
|
|||||||
|
|
||||||
.. versionadded:: 2.5 Added new-style gettext support.
|
.. versionadded:: 2.5 Added new-style gettext support.
|
||||||
|
|
||||||
.. method:: jinja.Environment.uninstall_gettext_translations()
|
.. method:: jinja2.Environment.uninstall_gettext_translations()
|
||||||
|
|
||||||
Uninstall the environment's globally installed translation.
|
Uninstall the environment's globally installed translation.
|
||||||
|
|
||||||
.. method:: jinja.Environment.extract_translations(source)
|
.. method:: jinja2.Environment.extract_translations(source)
|
||||||
|
|
||||||
Extract localizable strings from the given template node or source.
|
Extract localizable strings from the given template node or source.
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ installed when the environment is created.
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
translations = get_gettext_translations()
|
translations = get_gettext_translations()
|
||||||
env = Environment(extensions=["jinja.ext.i18n"])
|
env = Environment(extensions=["jinja2.ext.i18n"])
|
||||||
env.install_gettext_translations(translations)
|
env.install_gettext_translations(translations)
|
||||||
|
|
||||||
The ``get_gettext_translations`` function would return the translator
|
The ``get_gettext_translations`` function would return the translator
|
||||||
@ -182,7 +182,7 @@ The advantages of newstyle gettext are:
|
|||||||
Expression Statement
|
Expression Statement
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
**Import name:** ``jinja.ext.do``
|
**Import name:** ``jinja2.ext.do``
|
||||||
|
|
||||||
The "do" aka expression-statement extension adds a simple ``do`` tag to the
|
The "do" aka expression-statement extension adds a simple ``do`` tag to the
|
||||||
template engine that works like a variable expression but ignores the
|
template engine that works like a variable expression but ignores the
|
||||||
@ -193,7 +193,7 @@ return value.
|
|||||||
Loop Controls
|
Loop Controls
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
**Import name:** ``jinja.ext.loopcontrols``
|
**Import name:** ``jinja2.ext.loopcontrols``
|
||||||
|
|
||||||
This extension adds support for ``break`` and ``continue`` in loops. After
|
This extension adds support for ``break`` and ``continue`` in loops. After
|
||||||
enabling, Jinja provides those two keywords which work exactly like in
|
enabling, Jinja provides those two keywords which work exactly like in
|
||||||
@ -204,7 +204,7 @@ Python.
|
|||||||
With Statement
|
With Statement
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
**Import name:** ``jinja.ext.with_``
|
**Import name:** ``jinja2.ext.with_``
|
||||||
|
|
||||||
.. versionchanged:: 2.9
|
.. versionchanged:: 2.9
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ With Statement
|
|||||||
Autoescape Extension
|
Autoescape Extension
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
**Import name:** ``jinja.ext.autoescape``
|
**Import name:** ``jinja2.ext.autoescape``
|
||||||
|
|
||||||
.. versionchanged:: 2.9
|
.. versionchanged:: 2.9
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ Autoescape Extension
|
|||||||
Debug Extension
|
Debug Extension
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
**Import name:** ``jinja.ext.debug``
|
**Import name:** ``jinja2.ext.debug``
|
||||||
|
|
||||||
Adds a ``{% debug %}`` tag to dump the current context as well as the
|
Adds a ``{% debug %}`` tag to dump the current context as well as the
|
||||||
available filters and tests. This is useful to see what's available to
|
available filters and tests. This is useful to see what's available to
|
||||||
@ -240,7 +240,7 @@ use in the template without setting up a debugger.
|
|||||||
Writing Extensions
|
Writing Extensions
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
.. module:: jinja.ext
|
.. module:: jinja2.ext
|
||||||
|
|
||||||
By writing extensions you can add custom tags to Jinja. This is a non-trivial
|
By writing extensions you can add custom tags to Jinja. This is a non-trivial
|
||||||
task and usually not needed as the default tags and expressions cover all
|
task and usually not needed as the default tags and expressions cover all
|
||||||
@ -269,7 +269,7 @@ The following example implements a ``cache`` tag for Jinja by using the
|
|||||||
|
|
||||||
And here is how you use it in an environment::
|
And here is how you use it in an environment::
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from cachelib import SimpleCache
|
from cachelib import SimpleCache
|
||||||
|
|
||||||
env = Environment(extensions=[FragmentCacheExtension])
|
env = Environment(extensions=[FragmentCacheExtension])
|
||||||
@ -313,7 +313,7 @@ Extension API
|
|||||||
Extension
|
Extension
|
||||||
~~~~~~~~~
|
~~~~~~~~~
|
||||||
|
|
||||||
Extensions always have to extend the :class:`jinja.ext.Extension` class:
|
Extensions always have to extend the :class:`jinja2.ext.Extension` class:
|
||||||
|
|
||||||
.. autoclass:: Extension
|
.. autoclass:: Extension
|
||||||
:members: preprocess, filter_stream, parse, attr, call_method
|
:members: preprocess, filter_stream, parse, attr, call_method
|
||||||
@ -336,7 +336,7 @@ The parser passed to :meth:`Extension.parse` provides ways to parse
|
|||||||
expressions of different types. The following methods may be used by
|
expressions of different types. The following methods may be used by
|
||||||
extensions:
|
extensions:
|
||||||
|
|
||||||
.. autoclass:: jinja.parser.Parser
|
.. autoclass:: jinja2.parser.Parser
|
||||||
:members: parse_expression, parse_tuple, parse_assign_target,
|
:members: parse_expression, parse_tuple, parse_assign_target,
|
||||||
parse_statements, free_identifier, fail
|
parse_statements, free_identifier, fail
|
||||||
|
|
||||||
@ -353,16 +353,16 @@ extensions:
|
|||||||
|
|
||||||
.. attribute:: stream
|
.. attribute:: stream
|
||||||
|
|
||||||
The current :class:`~jinja.lexer.TokenStream`
|
The current :class:`~jinja2.lexer.TokenStream`
|
||||||
|
|
||||||
.. autoclass:: jinja.lexer.TokenStream
|
.. autoclass:: jinja2.lexer.TokenStream
|
||||||
:members: push, look, eos, skip, __next__, next_if, skip_if, expect
|
:members: push, look, eos, skip, __next__, next_if, skip_if, expect
|
||||||
|
|
||||||
.. attribute:: current
|
.. attribute:: current
|
||||||
|
|
||||||
The current :class:`~jinja.lexer.Token`.
|
The current :class:`~jinja2.lexer.Token`.
|
||||||
|
|
||||||
.. autoclass:: jinja.lexer.Token
|
.. autoclass:: jinja2.lexer.Token
|
||||||
:members: test, test_any
|
:members: test, test_any
|
||||||
|
|
||||||
.. attribute:: lineno
|
.. attribute:: lineno
|
||||||
@ -381,7 +381,7 @@ extensions:
|
|||||||
There is also a utility function in the lexer module that can count newline
|
There is also a utility function in the lexer module that can count newline
|
||||||
characters in strings:
|
characters in strings:
|
||||||
|
|
||||||
.. autofunction:: jinja.lexer.count_newlines
|
.. autofunction:: jinja2.lexer.count_newlines
|
||||||
|
|
||||||
|
|
||||||
AST
|
AST
|
||||||
@ -395,10 +395,10 @@ execute custom Python code.
|
|||||||
The list below describes all nodes that are currently available. The AST may
|
The list below describes all nodes that are currently available. The AST may
|
||||||
change between Jinja versions but will stay backwards compatible.
|
change between Jinja versions but will stay backwards compatible.
|
||||||
|
|
||||||
For more information have a look at the repr of :meth:`jinja.Environment.parse`.
|
For more information have a look at the repr of :meth:`jinja2.Environment.parse`.
|
||||||
|
|
||||||
.. module:: jinja.nodes
|
.. module:: jinja2.nodes
|
||||||
|
|
||||||
.. jinja:nodes:: jinja.nodes.Node
|
.. jinja:nodes:: jinja2.nodes.Node
|
||||||
|
|
||||||
.. autoexception:: Impossible
|
.. autoexception:: Impossible
|
||||||
|
@ -145,7 +145,7 @@ work in production environments::
|
|||||||
sandbox._WHITE_LIST_C_MODULES += ['_ctypes', 'gestalt']
|
sandbox._WHITE_LIST_C_MODULES += ['_ctypes', 'gestalt']
|
||||||
|
|
||||||
Credit for this snippet goes to `Thomas Johansson
|
Credit for this snippet goes to `Thomas Johansson
|
||||||
<https://stackoverflow.com/a/3694434>`_
|
<https://stackoverflow.com/questions/3086091/debug-jinja2-in-google-app-engine/3694434#3694434>`_
|
||||||
|
|
||||||
Why is there no Python 2.3/2.4/2.5/2.6/3.1/3.2/3.3 support?
|
Why is there no Python 2.3/2.4/2.5/2.6/3.1/3.2/3.3 support?
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
|
@ -14,7 +14,7 @@ Babel Integration
|
|||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
Jinja provides support for extracting gettext messages from templates via a
|
Jinja provides support for extracting gettext messages from templates via a
|
||||||
`Babel`_ extractor entry point called `jinja.ext.babel_extract`. The Babel
|
`Babel`_ extractor entry point called `jinja2.ext.babel_extract`. The Babel
|
||||||
support is implemented as part of the :ref:`i18n-extension` extension.
|
support is implemented as part of the :ref:`i18n-extension` extension.
|
||||||
|
|
||||||
Gettext messages extracted from both `trans` tags and code expressions.
|
Gettext messages extracted from both `trans` tags and code expressions.
|
||||||
@ -24,7 +24,7 @@ in its Babel extraction method `mapping file`_:
|
|||||||
|
|
||||||
.. sourcecode:: ini
|
.. sourcecode:: ini
|
||||||
|
|
||||||
[jinja: **/templates/**.html]
|
[jinja2: **/templates/**.html]
|
||||||
encoding = utf-8
|
encoding = utf-8
|
||||||
|
|
||||||
The syntax related options of the :class:`Environment` are also available as
|
The syntax related options of the :class:`Environment` are also available as
|
||||||
@ -33,7 +33,7 @@ that templates use ``%`` as `line_statement_prefix` you can use this code:
|
|||||||
|
|
||||||
.. sourcecode:: ini
|
.. sourcecode:: ini
|
||||||
|
|
||||||
[jinja: **/templates/**.html]
|
[jinja2: **/templates/**.html]
|
||||||
encoding = utf-8
|
encoding = utf-8
|
||||||
line_statement_prefix = %
|
line_statement_prefix = %
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ Pylons powered application.
|
|||||||
The template engine is configured in `config/environment.py`. The configuration
|
The template engine is configured in `config/environment.py`. The configuration
|
||||||
for Jinja looks something like that::
|
for Jinja looks something like that::
|
||||||
|
|
||||||
from jinja import Environment, PackageLoader
|
from jinja2 import Environment, PackageLoader
|
||||||
config['pylons.app_globals'].jinja_env = Environment(
|
config['pylons.app_globals'].jinja_env = Environment(
|
||||||
loader=PackageLoader('yourapplication', 'templates')
|
loader=PackageLoader('yourapplication', 'templates')
|
||||||
)
|
)
|
||||||
|
@ -9,29 +9,51 @@ Django, you should feel right at home with Jinja. It's both designer and
|
|||||||
developer friendly by sticking to Python's principles and adding functionality
|
developer friendly by sticking to Python's principles and adding functionality
|
||||||
useful for templating environments.
|
useful for templating environments.
|
||||||
|
|
||||||
|
|
||||||
Prerequisites
|
Prerequisites
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
Jinja works with Python >= 3.5 and 2.7.
|
Jinja works with Python 2.7.x and >= 3.5. If you are using Python
|
||||||
|
3.2 you can use an older release of Jinja (2.6) as support for Python 3.2
|
||||||
Jinja depends on `MarkupSafe`_. If you install via ``pip`` it will be
|
was dropped in Jinja version 2.7. The last release which supported Python 2.6
|
||||||
installed automatically.
|
and 3.3 was Jinja 2.10.
|
||||||
|
|
||||||
.. _MarkupSafe: https://markupsafe.palletsprojects.com/
|
|
||||||
|
|
||||||
|
If you wish to use the :class:`~jinja2.PackageLoader` class, you will also
|
||||||
|
need `setuptools`_ or `distribute`_ installed at runtime.
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
You can install the most recent Jinja version using `pip`_::
|
You can install the most recent Jinja version using `pip`_::
|
||||||
|
|
||||||
pip install Jinja
|
pip install Jinja2
|
||||||
|
|
||||||
This will install Jinja in your Python installation's site-packages directory.
|
This will install Jinja in your Python installation's site-packages directory.
|
||||||
|
|
||||||
.. _pip: https://pypi.org/project/pip/
|
Installing the development version
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
1. Install `git`_
|
||||||
|
2. ``git clone git://github.com/pallets/jinja.git``
|
||||||
|
3. ``cd jinja2``
|
||||||
|
4. ``ln -s jinja2 /usr/lib/python2.X/site-packages``
|
||||||
|
|
||||||
|
As an alternative to steps 4 you can also do ``python setup.py develop``
|
||||||
|
which will install the package via `distribute` in development mode. This also
|
||||||
|
has the advantage that the C extensions are compiled.
|
||||||
|
|
||||||
|
.. _distribute: https://pypi.org/project/distribute/
|
||||||
|
.. _setuptools: https://pypi.org/project/setuptools/
|
||||||
|
.. _pip: https://pypi.org/project/pip/
|
||||||
|
.. _git: https://git-scm.com/
|
||||||
|
|
||||||
|
|
||||||
|
MarkupSafe Dependency
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
As of version 2.7 Jinja depends on the `MarkupSafe`_ module. If you install
|
||||||
|
Jinja via ``pip`` it will be installed automatically for you.
|
||||||
|
|
||||||
|
.. _MarkupSafe: https://markupsafe.palletsprojects.com/
|
||||||
|
|
||||||
Basic API Usage
|
Basic API Usage
|
||||||
---------------
|
---------------
|
||||||
@ -40,17 +62,17 @@ This section gives you a brief introduction to the Python API for Jinja
|
|||||||
templates.
|
templates.
|
||||||
|
|
||||||
The most basic way to create a template and render it is through
|
The most basic way to create a template and render it is through
|
||||||
:class:`~jinja.Template`. This however is not the recommended way to
|
:class:`~jinja2.Template`. This however is not the recommended way to
|
||||||
work with it if your templates are not loaded from strings but the file
|
work with it if your templates are not loaded from strings but the file
|
||||||
system or another data source:
|
system or another data source:
|
||||||
|
|
||||||
>>> from jinja import Template
|
>>> from jinja2 import Template
|
||||||
>>> template = Template('Hello {{ name }}!')
|
>>> template = Template('Hello {{ name }}!')
|
||||||
>>> template.render(name='John Doe')
|
>>> template.render(name='John Doe')
|
||||||
u'Hello John Doe!'
|
u'Hello John Doe!'
|
||||||
|
|
||||||
By creating an instance of :class:`~jinja.Template` you get back a new template
|
By creating an instance of :class:`~jinja2.Template` you get back a new template
|
||||||
object that provides a method called :meth:`~jinja.Template.render` which when
|
object that provides a method called :meth:`~jinja2.Template.render` which when
|
||||||
called with a dict or keyword arguments expands the template. The dict
|
called with a dict or keyword arguments expands the template. The dict
|
||||||
or keywords arguments passed to the template are the so-called "context"
|
or keywords arguments passed to the template are the so-called "context"
|
||||||
of the template.
|
of the template.
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
.. module:: jinja.nativetypes
|
.. module:: jinja2.nativetypes
|
||||||
|
|
||||||
.. _nativetypes:
|
.. _nativetypes:
|
||||||
|
|
||||||
Native Python Types
|
Native Python Types
|
||||||
===================
|
===================
|
||||||
|
|
||||||
The default :class:`~jinja.Environment` renders templates to strings. With
|
The default :class:`~jinja2.Environment` renders templates to strings. With
|
||||||
:class:`NativeEnvironment`, rendering a template produces a native Python type.
|
:class:`NativeEnvironment`, rendering a template produces a native Python type.
|
||||||
This is useful if you are using Jinja outside the context of creating text
|
This is useful if you are using Jinja outside the context of creating text
|
||||||
files. For example, your code may have an intermediate step where users may use
|
files. For example, your code may have an intermediate step where users may use
|
||||||
|
@ -17,7 +17,7 @@ SecurityError: access to attribute 'func_code' of 'function' object is unsafe.
|
|||||||
API
|
API
|
||||||
---
|
---
|
||||||
|
|
||||||
.. module:: jinja.sandbox
|
.. module:: jinja2.sandbox
|
||||||
|
|
||||||
.. autoclass:: SandboxedEnvironment([options])
|
.. autoclass:: SandboxedEnvironment([options])
|
||||||
:members: is_safe_attribute, is_safe_callable, default_binop_table,
|
:members: is_safe_attribute, is_safe_callable, default_binop_table,
|
||||||
@ -77,7 +77,7 @@ operator symbols into callbacks performing the default operator behavior.
|
|||||||
This example shows how the power (``**``) operator can be disabled in
|
This example shows how the power (``**``) operator can be disabled in
|
||||||
Jinja::
|
Jinja::
|
||||||
|
|
||||||
from jinja.sandbox import SandboxedEnvironment
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
|
||||||
|
|
||||||
class MyEnvironment(SandboxedEnvironment):
|
class MyEnvironment(SandboxedEnvironment):
|
||||||
|
@ -1425,7 +1425,7 @@ is a bit contrived in the context of rendering a template):
|
|||||||
List of Builtin Filters
|
List of Builtin Filters
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
.. jinja:filters:: jinja.defaults.DEFAULT_FILTERS
|
.. jinja:filters:: jinja2.defaults.DEFAULT_FILTERS
|
||||||
|
|
||||||
|
|
||||||
.. _builtin-tests:
|
.. _builtin-tests:
|
||||||
@ -1433,7 +1433,7 @@ List of Builtin Filters
|
|||||||
List of Builtin Tests
|
List of Builtin Tests
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
.. jinja:tests:: jinja.defaults.DEFAULT_TESTS
|
.. jinja:tests:: jinja2.defaults.DEFAULT_TESTS
|
||||||
|
|
||||||
|
|
||||||
.. _builtin-globals:
|
.. _builtin-globals:
|
||||||
@ -1731,9 +1731,9 @@ without setting up a debugger.
|
|||||||
|
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
{'context': {'cycler': <class 'jinja.utils.Cycler'>,
|
{'context': {'cycler': <class 'jinja2.utils.Cycler'>,
|
||||||
...,
|
...,
|
||||||
'namespace': <class 'jinja.utils.Namespace'>},
|
'namespace': <class 'jinja2.utils.Namespace'>},
|
||||||
'filters': ['abs', 'attr', 'batch', 'capitalize', 'center', 'count', 'd',
|
'filters': ['abs', 'attr', 'batch', 'capitalize', 'center', 'count', 'd',
|
||||||
..., 'urlencode', 'urlize', 'wordcount', 'wordwrap', 'xmlattr'],
|
..., 'urlencode', 'urlize', 'wordcount', 'wordwrap', 'xmlattr'],
|
||||||
'tests': ['!=', '<', '<=', '==', '>', '>=', 'callable', 'defined',
|
'tests': ['!=', '<', '<=', '==', '>', '>=', 'callable', 'defined',
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
|
|
||||||
env = Environment(
|
env = Environment(
|
||||||
line_statement_prefix="#", variable_start_string="${", variable_end_string="}"
|
line_statement_prefix="#", variable_start_string="${", variable_end_string="}"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja.loaders import FileSystemLoader
|
from jinja2.loaders import FileSystemLoader
|
||||||
|
|
||||||
env = Environment(loader=FileSystemLoader("templates"))
|
env = Environment(loader=FileSystemLoader("templates"))
|
||||||
tmpl = env.get_template("broken.html")
|
tmpl = env.get_template("broken.html")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja.loaders import DictLoader
|
from jinja2.loaders import DictLoader
|
||||||
|
|
||||||
env = Environment(
|
env = Environment(
|
||||||
loader=DictLoader(
|
loader=DictLoader(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja.loaders import DictLoader
|
from jinja2.loaders import DictLoader
|
||||||
|
|
||||||
env = Environment(
|
env = Environment(
|
||||||
loader=DictLoader(
|
loader=DictLoader(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
|
|
||||||
env = Environment(
|
env = Environment(
|
||||||
line_statement_prefix="%", variable_start_string="${", variable_end_string="}"
|
line_statement_prefix="%", variable_start_string="${", variable_end_string="}"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
|
|
||||||
tmpl = Environment().from_string(
|
tmpl = Environment().from_string(
|
||||||
"""\
|
"""\
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
|
|
||||||
env = Environment(extensions=["jinja.ext.i18n"])
|
env = Environment(extensions=["jinja2.ext.i18n"])
|
||||||
env.globals["gettext"] = {"Hello %(user)s!": "Hallo %(user)s!"}.__getitem__
|
env.globals["gettext"] = {"Hello %(user)s!": "Hallo %(user)s!"}.__getitem__
|
||||||
env.globals["ngettext"] = lambda s, p, n: {
|
env.globals["ngettext"] = lambda s, p, n: {
|
||||||
"%(count)s user": "%(count)d Benutzer",
|
"%(count)s user": "%(count)d Benutzer",
|
||||||
|
@ -58,10 +58,12 @@ def build_pattern(ranges):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Build the regex pattern and write it to ``_identifier.py``."""
|
"""Build the regex pattern and write it to
|
||||||
|
``jinja2/_identifier.py``.
|
||||||
|
"""
|
||||||
pattern = build_pattern(collapse_ranges(get_characters()))
|
pattern = build_pattern(collapse_ranges(get_characters()))
|
||||||
filename = os.path.abspath(
|
filename = os.path.abspath(
|
||||||
os.path.join(os.path.dirname(__file__), "..", "src", "jinja", "_identifier.py")
|
os.path.join(os.path.dirname(__file__), "..", "src", "jinja2", "_identifier.py")
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(filename, "w", encoding="utf8") as f:
|
with open(filename, "w", encoding="utf8") as f:
|
||||||
|
12
setup.cfg
12
setup.cfg
@ -8,19 +8,19 @@ universal = true
|
|||||||
testpaths = tests
|
testpaths = tests
|
||||||
filterwarnings =
|
filterwarnings =
|
||||||
error
|
error
|
||||||
ignore:the sets module:DeprecationWarning:jinja.sandbox
|
ignore:the sets module:DeprecationWarning:jinja2.sandbox
|
||||||
|
|
||||||
[coverage:run]
|
[coverage:run]
|
||||||
branch = True
|
branch = True
|
||||||
source =
|
source =
|
||||||
jinja
|
jinja2
|
||||||
tests
|
tests
|
||||||
|
|
||||||
[coverage:paths]
|
[coverage:paths]
|
||||||
source =
|
source =
|
||||||
src/jinja
|
src/jinja2
|
||||||
.tox/*/lib/python*/site-packages/jinja
|
.tox/*/lib/python*/site-packages/jinja2
|
||||||
.tox/*/site-packages/jinja
|
.tox/*/site-packages/jinja2
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# B = bugbear
|
# B = bugbear
|
||||||
@ -42,4 +42,4 @@ ignore =
|
|||||||
max-line-length = 80
|
max-line-length = 80
|
||||||
per-file-ignores =
|
per-file-ignores =
|
||||||
# __init__ module exports names
|
# __init__ module exports names
|
||||||
src/jinja/__init__.py: F401
|
src/jinja2/__init__.py: F401
|
||||||
|
6
setup.py
6
setup.py
@ -7,11 +7,11 @@ from setuptools import setup
|
|||||||
with io.open("README.rst", "rt", encoding="utf8") as f:
|
with io.open("README.rst", "rt", encoding="utf8") as f:
|
||||||
readme = f.read()
|
readme = f.read()
|
||||||
|
|
||||||
with io.open("src/jinja/__init__.py", "rt", encoding="utf8") as f:
|
with io.open("src/jinja2/__init__.py", "rt", encoding="utf8") as f:
|
||||||
version = re.search(r'__version__ = "(.*?)"', f.read(), re.M).group(1)
|
version = re.search(r'__version__ = "(.*?)"', f.read(), re.M).group(1)
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="Jinja",
|
name="Jinja2",
|
||||||
version=version,
|
version=version,
|
||||||
url="https://palletsprojects.com/p/jinja/",
|
url="https://palletsprojects.com/p/jinja/",
|
||||||
project_urls={
|
project_urls={
|
||||||
@ -51,5 +51,5 @@ setup(
|
|||||||
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
|
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*",
|
||||||
install_requires=["MarkupSafe>=0.23"],
|
install_requires=["MarkupSafe>=0.23"],
|
||||||
extras_require={"i18n": ["Babel>=0.8"]},
|
extras_require={"i18n": ["Babel>=0.8"]},
|
||||||
entry_points={"babel.extractors": ["jinja = jinja.ext:babel_extract[i18n]"]},
|
entry_points={"babel.extractors": ["jinja2 = jinja2.ext:babel_extract[i18n]"]},
|
||||||
)
|
)
|
||||||
|
@ -23,14 +23,17 @@ from ._compat import pickle
|
|||||||
from ._compat import text_type
|
from ._compat import text_type
|
||||||
from .utils import open_if_exists
|
from .utils import open_if_exists
|
||||||
|
|
||||||
bc_version = 4
|
bc_version = 3
|
||||||
# Magic bytes to identify Jinja bytecode cache files. Contains the
|
|
||||||
# Python major and minor version to avoid loading incompatible bytecode
|
# magic version used to only change with new jinja versions. With 2.6
|
||||||
# if a project upgrades its Python version.
|
# we change this to also take Python version changes into account. The
|
||||||
|
# reason for this is that Python tends to segfault if fed earlier bytecode
|
||||||
|
# versions because someone thought it would be a good idea to reuse opcodes
|
||||||
|
# or make Python incompatible with earlier versions.
|
||||||
bc_magic = (
|
bc_magic = (
|
||||||
b"jinja"
|
"j2".encode("ascii")
|
||||||
+ pickle.dumps(bc_version, 2)
|
+ pickle.dumps(bc_version, 2)
|
||||||
+ pickle.dumps((sys.version_info[0] << 24) | sys.version_info[1], 2)
|
+ pickle.dumps((sys.version_info[0] << 24) | sys.version_info[1])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -94,7 +97,7 @@ class Bucket(object):
|
|||||||
class BytecodeCache(object):
|
class BytecodeCache(object):
|
||||||
"""To implement your own bytecode cache you have to subclass this class
|
"""To implement your own bytecode cache you have to subclass this class
|
||||||
and override :meth:`load_bytecode` and :meth:`dump_bytecode`. Both of
|
and override :meth:`load_bytecode` and :meth:`dump_bytecode`. Both of
|
||||||
these methods are passed a :class:`Bucket`.
|
these methods are passed a :class:`~jinja2.bccache.Bucket`.
|
||||||
|
|
||||||
A very basic bytecode cache that saves the bytecode on the file system::
|
A very basic bytecode cache that saves the bytecode on the file system::
|
||||||
|
|
||||||
@ -179,20 +182,15 @@ class FileSystemBytecodeCache(BytecodeCache):
|
|||||||
is created for the user in the system temp directory.
|
is created for the user in the system temp directory.
|
||||||
|
|
||||||
The pattern can be used to have multiple separate caches operate on the
|
The pattern can be used to have multiple separate caches operate on the
|
||||||
same directory. The default pattern is ``'__jinja_%s.cache'``. ``%s``
|
same directory. The default pattern is ``'__jinja2_%s.cache'``. ``%s``
|
||||||
is replaced with the cache key.
|
is replaced with the cache key.
|
||||||
|
|
||||||
>>> bcc = FileSystemBytecodeCache('/tmp/jinja_cache', '%s.cache')
|
>>> bcc = FileSystemBytecodeCache('/tmp/jinja_cache', '%s.cache')
|
||||||
|
|
||||||
This bytecode cache supports clearing of the cache using the clear method.
|
This bytecode cache supports clearing of the cache using the clear method.
|
||||||
|
|
||||||
.. versionchanged:; 2.11
|
|
||||||
The default cache directory was renamed to
|
|
||||||
``_jinja-cache-{uid}``. The default filename pattern was renamed
|
|
||||||
to ``__jinja_%s.cache``.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, directory=None, pattern="__jinja_%s.cache"):
|
def __init__(self, directory=None, pattern="__jinja2_%s.cache"):
|
||||||
if directory is None:
|
if directory is None:
|
||||||
directory = self._get_default_cache_dir()
|
directory = self._get_default_cache_dir()
|
||||||
self.directory = directory
|
self.directory = directory
|
||||||
@ -214,7 +212,7 @@ class FileSystemBytecodeCache(BytecodeCache):
|
|||||||
if not hasattr(os, "getuid"):
|
if not hasattr(os, "getuid"):
|
||||||
_unsafe_dir()
|
_unsafe_dir()
|
||||||
|
|
||||||
dirname = "_jinja-cache-%d" % os.getuid()
|
dirname = "_jinja2-cache-%d" % os.getuid()
|
||||||
actual_dir = os.path.join(tmpdir, dirname)
|
actual_dir = os.path.join(tmpdir, dirname)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -317,18 +315,15 @@ class MemcachedBytecodeCache(BytecodeCache):
|
|||||||
This bytecode cache does not support clearing of used items in the cache.
|
This bytecode cache does not support clearing of used items in the cache.
|
||||||
The clear method is a no-operation function.
|
The clear method is a no-operation function.
|
||||||
|
|
||||||
.. versionchanged:: 2.11
|
.. versionadded:: 2.7
|
||||||
The default prefix was renamed to ``jinja/bytecode/``.
|
|
||||||
|
|
||||||
.. versionchanged:: 2.7
|
|
||||||
Added support for ignoring memcache errors through the
|
Added support for ignoring memcache errors through the
|
||||||
``ignore_memcache_errors`` parameter.
|
`ignore_memcache_errors` parameter.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
client,
|
client,
|
||||||
prefix="jinja/bytecode/",
|
prefix="jinja2/bytecode/",
|
||||||
timeout=None,
|
timeout=None,
|
||||||
ignore_memcache_errors=True,
|
ignore_memcache_errors=True,
|
||||||
):
|
):
|
||||||
|
@ -715,11 +715,11 @@ class CodeGenerator(NodeVisitor):
|
|||||||
from .runtime import __all__ as exported
|
from .runtime import __all__ as exported
|
||||||
|
|
||||||
self.writeline("from __future__ import %s" % ", ".join(code_features))
|
self.writeline("from __future__ import %s" % ", ".join(code_features))
|
||||||
self.writeline("from jinja.runtime import " + ", ".join(exported))
|
self.writeline("from jinja2.runtime import " + ", ".join(exported))
|
||||||
|
|
||||||
if self.environment.is_async:
|
if self.environment.is_async:
|
||||||
self.writeline(
|
self.writeline(
|
||||||
"from jinja.asyncsupport import auto_await, "
|
"from jinja2.asyncsupport import auto_await, "
|
||||||
"auto_aiter, AsyncLoopContext"
|
"auto_aiter, AsyncLoopContext"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ class Environment(object):
|
|||||||
`autoescape`
|
`autoescape`
|
||||||
If set to ``True`` the XML/HTML autoescaping feature is enabled by
|
If set to ``True`` the XML/HTML autoescaping feature is enabled by
|
||||||
default. For more details about autoescaping see
|
default. For more details about autoescaping see
|
||||||
:class:`~markupsafe.Markup`. This can also
|
:class:`~jinja2.utils.Markup`. As of Jinja 2.4 this can also
|
||||||
be a callable that is passed the template name and has to
|
be a callable that is passed the template name and has to
|
||||||
return ``True`` or ``False`` depending on autoescape should be
|
return ``True`` or ``False`` depending on autoescape should be
|
||||||
enabled by default.
|
enabled by default.
|
||||||
@ -262,7 +262,7 @@ class Environment(object):
|
|||||||
|
|
||||||
#: if this environment is sandboxed. Modifying this variable won't make
|
#: if this environment is sandboxed. Modifying this variable won't make
|
||||||
#: the environment sandboxed though. For a real sandboxed environment
|
#: the environment sandboxed though. For a real sandboxed environment
|
||||||
#: have a look at jinja.sandbox. This flag alone controls the code
|
#: have a look at jinja2.sandbox. This flag alone controls the code
|
||||||
#: generation by the compiler.
|
#: generation by the compiler.
|
||||||
sandboxed = False
|
sandboxed = False
|
||||||
|
|
||||||
@ -277,11 +277,11 @@ class Environment(object):
|
|||||||
shared = False
|
shared = False
|
||||||
|
|
||||||
#: the class that is used for code generation. See
|
#: the class that is used for code generation. See
|
||||||
#: :class:`~jinja.compiler.CodeGenerator` for more information.
|
#: :class:`~jinja2.compiler.CodeGenerator` for more information.
|
||||||
code_generator_class = CodeGenerator
|
code_generator_class = CodeGenerator
|
||||||
|
|
||||||
#: the context class thatis used for templates. See
|
#: the context class thatis used for templates. See
|
||||||
#: :class:`~jinja.runtime.Context` for more information.
|
#: :class:`~jinja2.runtime.Context` for more information.
|
||||||
context_class = Context
|
context_class = Context
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -566,7 +566,7 @@ class Environment(object):
|
|||||||
|
|
||||||
def _tokenize(self, source, name, filename=None, state=None):
|
def _tokenize(self, source, name, filename=None, state=None):
|
||||||
"""Called by the parser to do the preprocessing and filtering
|
"""Called by the parser to do the preprocessing and filtering
|
||||||
for all the extensions. Returns a :class:`~jinja.lexer.TokenStream`.
|
for all the extensions. Returns a :class:`~jinja2.lexer.TokenStream`.
|
||||||
"""
|
"""
|
||||||
source = self.preprocess(source, name, filename)
|
source = self.preprocess(source, name, filename)
|
||||||
stream = self.lexer.tokenize(source, name, filename, state)
|
stream = self.lexer.tokenize(source, name, filename, state)
|
||||||
@ -1254,7 +1254,7 @@ class TemplateModule(object):
|
|||||||
|
|
||||||
|
|
||||||
class TemplateExpression(object):
|
class TemplateExpression(object):
|
||||||
"""The :meth:`jinja.Environment.compile_expression` method returns an
|
"""The :meth:`jinja2.Environment.compile_expression` method returns an
|
||||||
instance of this object. It encapsulates the expression-like access
|
instance of this object. It encapsulates the expression-like access
|
||||||
to the template with an expression it wraps.
|
to the template with an expression it wraps.
|
||||||
"""
|
"""
|
||||||
|
@ -93,10 +93,10 @@ class Extension(with_metaclass(ExtensionRegistry, object)):
|
|||||||
return source
|
return source
|
||||||
|
|
||||||
def filter_stream(self, stream):
|
def filter_stream(self, stream):
|
||||||
"""It's passed a :class:`~jinja.lexer.TokenStream` that can be used
|
"""It's passed a :class:`~jinja2.lexer.TokenStream` that can be used
|
||||||
to filter tokens returned. This method has to return an iterable of
|
to filter tokens returned. This method has to return an iterable of
|
||||||
:class:`~jinja.lexer.Token`\\s, but it doesn't have to return a
|
:class:`~jinja2.lexer.Token`\\s, but it doesn't have to return a
|
||||||
:class:`~jinja.lexer.TokenStream`.
|
:class:`~jinja2.lexer.TokenStream`.
|
||||||
"""
|
"""
|
||||||
return stream
|
return stream
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ class Extension(with_metaclass(ExtensionRegistry, object)):
|
|||||||
self, name, args=None, kwargs=None, dyn_args=None, dyn_kwargs=None, lineno=None
|
self, name, args=None, kwargs=None, dyn_args=None, dyn_kwargs=None, lineno=None
|
||||||
):
|
):
|
||||||
"""Call a method of the extension. This is a shortcut for
|
"""Call a method of the extension. This is a shortcut for
|
||||||
:meth:`attr` + :class:`jinja.nodes.Call`.
|
:meth:`attr` + :class:`jinja2.nodes.Call`.
|
||||||
"""
|
"""
|
||||||
if args is None:
|
if args is None:
|
||||||
args = []
|
args = []
|
||||||
@ -476,9 +476,9 @@ class DebugExtension(Extension):
|
|||||||
|
|
||||||
.. code-block:: text
|
.. code-block:: text
|
||||||
|
|
||||||
{'context': {'cycler': <class 'jinja.utils.Cycler'>,
|
{'context': {'cycler': <class 'jinja2.utils.Cycler'>,
|
||||||
...,
|
...,
|
||||||
'namespace': <class 'jinja.utils.Namespace'>},
|
'namespace': <class 'jinja2.utils.Namespace'>},
|
||||||
'filters': ['abs', 'attr', 'batch', 'capitalize', 'center', 'count', 'd',
|
'filters': ['abs', 'attr', 'batch', 'capitalize', 'center', 'count', 'd',
|
||||||
..., 'urlencode', 'urlize', 'wordcount', 'wordwrap', 'xmlattr'],
|
..., 'urlencode', 'urlize', 'wordcount', 'wordwrap', 'xmlattr'],
|
||||||
'tests': ['!=', '<', '<=', '==', '>', '>=', 'callable', 'defined',
|
'tests': ['!=', '<', '<=', '==', '>', '>=', 'callable', 'defined',
|
||||||
@ -523,7 +523,7 @@ def extract_from_ast(node, gettext_functions=GETTEXT_FUNCTIONS, babel_style=True
|
|||||||
|
|
||||||
This example explains the behavior:
|
This example explains the behavior:
|
||||||
|
|
||||||
>>> from jinja import Environment
|
>>> from jinja2 import Environment
|
||||||
>>> env = Environment()
|
>>> env = Environment()
|
||||||
>>> node = env.parse('{{ (_("foo"), _(), ngettext("foo", "bar", 42)) }}')
|
>>> node = env.parse('{{ (_("foo"), _(), ngettext("foo", "bar", 42)) }}')
|
||||||
>>> list(extract_from_ast(node))
|
>>> list(extract_from_ast(node))
|
||||||
|
@ -438,10 +438,10 @@ def do_default(value, default_value=u"", boolean=False):
|
|||||||
{{ ''|default('the string was empty', true) }}
|
{{ ''|default('the string was empty', true) }}
|
||||||
|
|
||||||
.. versionchanged:: 2.11
|
.. versionchanged:: 2.11
|
||||||
It's now possible to configure the :class:`~jinja.Environment` with
|
It's now possible to configure the :class:`~jinja2.Environment` with
|
||||||
:class:`~jinja.ChainableUndefined` to make the `default` filter work
|
:class:`~jinja2.ChainableUndefined` to make the `default` filter work
|
||||||
on nested elements and attributes that may contain undefined values
|
on nested elements and attributes that may contain undefined values
|
||||||
in the chain without getting an :exc:`~jinja.UndefinedError`.
|
in the chain without getting an :exc:`~jinja2.UndefinedError`.
|
||||||
"""
|
"""
|
||||||
if isinstance(value, Undefined) or (boolean and not value):
|
if isinstance(value, Undefined) or (boolean and not value):
|
||||||
return default_value
|
return default_value
|
||||||
|
@ -397,7 +397,7 @@ class TokenStream(object):
|
|||||||
|
|
||||||
def expect(self, expr):
|
def expect(self, expr):
|
||||||
"""Expect a given token type and return it. This accepts the same
|
"""Expect a given token type and return it. This accepts the same
|
||||||
argument as :meth:`jinja.lexer.Token.test`.
|
argument as :meth:`jinja2.lexer.Token.test`.
|
||||||
"""
|
"""
|
||||||
if not self.current.test(expr):
|
if not self.current.test(expr):
|
||||||
expr = describe_token_expr(expr)
|
expr = describe_token_expr(expr)
|
||||||
|
@ -46,7 +46,7 @@ class BaseLoader(object):
|
|||||||
A very basic example for a loader that looks up templates on the file
|
A very basic example for a loader that looks up templates on the file
|
||||||
system could look like this::
|
system could look like this::
|
||||||
|
|
||||||
from jinja import BaseLoader, TemplateNotFound
|
from jinja2 import BaseLoader, TemplateNotFound
|
||||||
from os.path import join, exists, getmtime
|
from os.path import join, exists, getmtime
|
||||||
|
|
||||||
class MyLoader(BaseLoader):
|
class MyLoader(BaseLoader):
|
||||||
@ -523,7 +523,7 @@ class ModuleLoader(BaseLoader):
|
|||||||
has_source_access = False
|
has_source_access = False
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
package_name = "_jinja_module_templates_%x" % id(self)
|
package_name = "_jinja2_module_templates_%x" % id(self)
|
||||||
|
|
||||||
# create a fake module that looks for the templates in the
|
# create a fake module that looks for the templates in the
|
||||||
# path given.
|
# path given.
|
||||||
|
@ -32,7 +32,7 @@ def find_undeclared_variables(ast):
|
|||||||
variables will be used depending on the path the execution takes at
|
variables will be used depending on the path the execution takes at
|
||||||
runtime, all variables are returned.
|
runtime, all variables are returned.
|
||||||
|
|
||||||
>>> from jinja import Environment, meta
|
>>> from jinja2 import Environment, meta
|
||||||
>>> env = Environment()
|
>>> env = Environment()
|
||||||
>>> ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')
|
>>> ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')
|
||||||
>>> meta.find_undeclared_variables(ast) == set(['bar'])
|
>>> meta.find_undeclared_variables(ast) == set(['bar'])
|
||||||
@ -56,7 +56,7 @@ def find_referenced_templates(ast):
|
|||||||
imports. If dynamic inheritance or inclusion is used, `None` will be
|
imports. If dynamic inheritance or inclusion is used, `None` will be
|
||||||
yielded.
|
yielded.
|
||||||
|
|
||||||
>>> from jinja import Environment, meta
|
>>> from jinja2 import Environment, meta
|
||||||
>>> env = Environment()
|
>>> env = Environment()
|
||||||
>>> ast = env.parse('{% extends "layout.html" %}{% include helper %}')
|
>>> ast = env.parse('{% extends "layout.html" %}{% include helper %}')
|
||||||
>>> list(meta.find_referenced_templates(ast))
|
>>> list(meta.find_referenced_templates(ast))
|
||||||
|
@ -937,7 +937,7 @@ class ExtensionAttribute(Expr):
|
|||||||
The identifier is the identifier of the :class:`Extension`.
|
The identifier is the identifier of the :class:`Extension`.
|
||||||
|
|
||||||
This node is usually constructed by calling the
|
This node is usually constructed by calling the
|
||||||
:meth:`~jinja.ext.Extension.attr` method on an extension.
|
:meth:`~jinja2.ext.Extension.attr` method on an extension.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fields = ("identifier", "name")
|
fields = ("identifier", "name")
|
||||||
@ -956,7 +956,7 @@ class ImportedName(Expr):
|
|||||||
class InternalName(Expr):
|
class InternalName(Expr):
|
||||||
"""An internal name in the compiler. You cannot create these nodes
|
"""An internal name in the compiler. You cannot create these nodes
|
||||||
yourself but the parser provides a
|
yourself but the parser provides a
|
||||||
:meth:`~jinja.parser.Parser.free_identifier` method that creates
|
:meth:`~jinja2.parser.Parser.free_identifier` method that creates
|
||||||
a new identifier for you. This identifier is not available from the
|
a new identifier for you. This identifier is not available from the
|
||||||
template and is not threated specially by the compiler.
|
template and is not threated specially by the compiler.
|
||||||
"""
|
"""
|
||||||
@ -1002,7 +1002,7 @@ class MarkSafeIfAutoescape(Expr):
|
|||||||
class ContextReference(Expr):
|
class ContextReference(Expr):
|
||||||
"""Returns the current template context. It can be used like a
|
"""Returns the current template context. It can be used like a
|
||||||
:class:`Name` node, with a ``'load'`` ctx and will return the
|
:class:`Name` node, with a ``'load'`` ctx and will return the
|
||||||
current :class:`~jinja.runtime.Context` object.
|
current :class:`~jinja2.runtime.Context` object.
|
||||||
|
|
||||||
Here an example that assigns the current template name to a
|
Here an example that assigns the current template name to a
|
||||||
variable named `foo`::
|
variable named `foo`::
|
||||||
@ -1011,7 +1011,7 @@ class ContextReference(Expr):
|
|||||||
Getattr(ContextReference(), 'name'))
|
Getattr(ContextReference(), 'name'))
|
||||||
|
|
||||||
This is basically equivalent to using the
|
This is basically equivalent to using the
|
||||||
:func:`~jinja.contextfunction` decorator when using the
|
:func:`~jinja2.contextfunction` decorator when using the
|
||||||
high-level API, which causes a reference to the context to be passed
|
high-level API, which causes a reference to the context to be passed
|
||||||
as the first argument to a function.
|
as the first argument to a function.
|
||||||
"""
|
"""
|
||||||
@ -1072,7 +1072,7 @@ class EvalContextModifier(Stmt):
|
|||||||
class ScopedEvalContextModifier(EvalContextModifier):
|
class ScopedEvalContextModifier(EvalContextModifier):
|
||||||
"""Modifies the eval context and reverts it later. Works exactly like
|
"""Modifies the eval context and reverts it later. Works exactly like
|
||||||
:class:`EvalContextModifier` but will only modify the
|
:class:`EvalContextModifier` but will only modify the
|
||||||
:class:`~jinja.nodes.EvalContext` for nodes in the :attr:`body`.
|
:class:`~jinja2.nodes.EvalContext` for nodes in the :attr:`body`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fields = ("body",)
|
fields = ("body",)
|
||||||
|
@ -123,7 +123,7 @@ class Parser(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def free_identifier(self, lineno=None):
|
def free_identifier(self, lineno=None):
|
||||||
"""Return a new free identifier as :class:`~jinja.nodes.InternalName`."""
|
"""Return a new free identifier as :class:`~jinja2.nodes.InternalName`."""
|
||||||
self._last_identifier += 1
|
self._last_identifier += 1
|
||||||
rv = object.__new__(nodes.InternalName)
|
rv = object.__new__(nodes.InternalName)
|
||||||
nodes.Node.__init__(rv, "fi%d" % self._last_identifier, lineno=lineno)
|
nodes.Node.__init__(rv, "fi%d" % self._last_identifier, lineno=lineno)
|
||||||
@ -607,7 +607,7 @@ class Parser(object):
|
|||||||
explicit_parentheses=False,
|
explicit_parentheses=False,
|
||||||
):
|
):
|
||||||
"""Works like `parse_expression` but if multiple expressions are
|
"""Works like `parse_expression` but if multiple expressions are
|
||||||
delimited by a comma a :class:`~jinja.nodes.Tuple` node is created.
|
delimited by a comma a :class:`~jinja2.nodes.Tuple` node is created.
|
||||||
This method could also return a regular expression instead of a tuple
|
This method could also return a regular expression instead of a tuple
|
||||||
if no commas where found.
|
if no commas where found.
|
||||||
|
|
||||||
|
@ -701,7 +701,7 @@ class Undefined(object):
|
|||||||
>>> foo + 42
|
>>> foo + 42
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
jinja.exceptions.UndefinedError: 'foo' is undefined
|
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
@ -926,7 +926,7 @@ class ChainableUndefined(Undefined):
|
|||||||
>>> foo.bar['baz'] + 42
|
>>> foo.bar['baz'] + 42
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
jinja.exceptions.UndefinedError: 'foo' is undefined
|
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
||||||
|
|
||||||
.. versionadded:: 2.11.0
|
.. versionadded:: 2.11.0
|
||||||
"""
|
"""
|
||||||
@ -954,7 +954,7 @@ class DebugUndefined(Undefined):
|
|||||||
>>> foo + 42
|
>>> foo + 42
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
jinja.exceptions.UndefinedError: 'foo' is undefined
|
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
@ -980,15 +980,15 @@ class StrictUndefined(Undefined):
|
|||||||
>>> str(foo)
|
>>> str(foo)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
jinja.exceptions.UndefinedError: 'foo' is undefined
|
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
||||||
>>> not foo
|
>>> not foo
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
jinja.exceptions.UndefinedError: 'foo' is undefined
|
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
||||||
>>> foo + 42
|
>>> foo + 42
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
jinja.exceptions.UndefinedError: 'foo' is undefined
|
jinja2.exceptions.UndefinedError: 'foo' is undefined
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
@ -197,7 +197,7 @@ def is_internal_attribute(obj, attr):
|
|||||||
python objects. This is useful if the environment method
|
python objects. This is useful if the environment method
|
||||||
:meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.
|
:meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.
|
||||||
|
|
||||||
>>> from jinja.sandbox import is_internal_attribute
|
>>> from jinja2.sandbox import is_internal_attribute
|
||||||
>>> is_internal_attribute(str, "mro")
|
>>> is_internal_attribute(str, "mro")
|
||||||
True
|
True
|
||||||
>>> is_internal_attribute(str, "upper")
|
>>> is_internal_attribute(str, "upper")
|
||||||
|
@ -543,7 +543,7 @@ def select_autoescape(
|
|||||||
If you want to enable it for all templates created from strings or
|
If you want to enable it for all templates created from strings or
|
||||||
for all templates with `.html` and `.xml` extensions::
|
for all templates with `.html` and `.xml` extensions::
|
||||||
|
|
||||||
from jinja import Environment, select_autoescape
|
from jinja2 import Environment, select_autoescape
|
||||||
env = Environment(autoescape=select_autoescape(
|
env = Environment(autoescape=select_autoescape(
|
||||||
enabled_extensions=('html', 'xml'),
|
enabled_extensions=('html', 'xml'),
|
||||||
default_for_string=True,
|
default_for_string=True,
|
||||||
@ -552,7 +552,7 @@ def select_autoescape(
|
|||||||
Example configuration to turn it on at all times except if the template
|
Example configuration to turn it on at all times except if the template
|
||||||
ends with `.txt`::
|
ends with `.txt`::
|
||||||
|
|
||||||
from jinja import Environment, select_autoescape
|
from jinja2 import Environment, select_autoescape
|
||||||
env = Environment(autoescape=select_autoescape(
|
env = Environment(autoescape=select_autoescape(
|
||||||
disabled_extensions=('txt',),
|
disabled_extensions=('txt',),
|
||||||
default_for_string=True,
|
default_for_string=True,
|
||||||
@ -719,7 +719,7 @@ def soft_unicode(s):
|
|||||||
from markupsafe import soft_unicode
|
from markupsafe import soft_unicode
|
||||||
|
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"'jinja.utils.soft_unicode' will be removed in version 3.0."
|
"'jinja2.utils.soft_unicode' will be removed in version 3.0."
|
||||||
" Use 'markupsafe.soft_unicode' instead.",
|
" Use 'markupsafe.soft_unicode' instead.",
|
||||||
DeprecationWarning,
|
DeprecationWarning,
|
||||||
stacklevel=2,
|
stacklevel=2,
|
||||||
|
@ -3,9 +3,9 @@ import os
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import loaders
|
from jinja2 import loaders
|
||||||
from jinja.utils import have_async_gen
|
from jinja2.utils import have_async_gen
|
||||||
|
|
||||||
|
|
||||||
def pytest_ignore_collect(path):
|
def pytest_ignore_collect(path):
|
||||||
|
@ -5,31 +5,31 @@ import tempfile
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import ChainableUndefined
|
from jinja2 import ChainableUndefined
|
||||||
from jinja import DebugUndefined
|
from jinja2 import DebugUndefined
|
||||||
from jinja import DictLoader
|
from jinja2 import DictLoader
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import is_undefined
|
from jinja2 import is_undefined
|
||||||
from jinja import make_logging_undefined
|
from jinja2 import make_logging_undefined
|
||||||
from jinja import meta
|
from jinja2 import meta
|
||||||
from jinja import StrictUndefined
|
from jinja2 import StrictUndefined
|
||||||
from jinja import Template
|
from jinja2 import Template
|
||||||
from jinja import TemplatesNotFound
|
from jinja2 import TemplatesNotFound
|
||||||
from jinja import Undefined
|
from jinja2 import Undefined
|
||||||
from jinja import UndefinedError
|
from jinja2 import UndefinedError
|
||||||
from jinja.compiler import CodeGenerator
|
from jinja2.compiler import CodeGenerator
|
||||||
from jinja.runtime import Context
|
from jinja2.runtime import Context
|
||||||
from jinja.utils import contextfunction
|
from jinja2.utils import contextfunction
|
||||||
from jinja.utils import Cycler
|
from jinja2.utils import Cycler
|
||||||
from jinja.utils import environmentfunction
|
from jinja2.utils import environmentfunction
|
||||||
from jinja.utils import evalcontextfunction
|
from jinja2.utils import evalcontextfunction
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.api
|
@pytest.mark.api
|
||||||
@pytest.mark.extended
|
@pytest.mark.extended
|
||||||
class TestExtendedAPI(object):
|
class TestExtendedAPI(object):
|
||||||
def test_item_and_attribute(self, env):
|
def test_item_and_attribute(self, env):
|
||||||
from jinja.sandbox import SandboxedEnvironment
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
|
|
||||||
for env in Environment(), SandboxedEnvironment():
|
for env in Environment(), SandboxedEnvironment():
|
||||||
# the |list is necessary for python3
|
# the |list is necessary for python3
|
||||||
@ -154,7 +154,7 @@ class TestExtendedAPI(object):
|
|||||||
assert t.render(foo="<foo>") == "<foo>"
|
assert t.render(foo="<foo>") == "<foo>"
|
||||||
|
|
||||||
def test_sandbox_max_range(self, env):
|
def test_sandbox_max_range(self, env):
|
||||||
from jinja.sandbox import SandboxedEnvironment, MAX_RANGE
|
from jinja2.sandbox import SandboxedEnvironment, MAX_RANGE
|
||||||
|
|
||||||
env = SandboxedEnvironment()
|
env = SandboxedEnvironment()
|
||||||
t = env.from_string("{% for item in range(total) %}{{ item }}{% endfor %}")
|
t = env.from_string("{% for item in range(total) %}{{ item }}{% endfor %}")
|
||||||
|
@ -2,13 +2,13 @@ import asyncio
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import DictLoader
|
from jinja2 import DictLoader
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import Template
|
from jinja2 import Template
|
||||||
from jinja.asyncsupport import auto_aiter
|
from jinja2.asyncsupport import auto_aiter
|
||||||
from jinja.exceptions import TemplateNotFound
|
from jinja2.exceptions import TemplateNotFound
|
||||||
from jinja.exceptions import TemplatesNotFound
|
from jinja2.exceptions import TemplatesNotFound
|
||||||
from jinja.exceptions import UndefinedError
|
from jinja2.exceptions import UndefinedError
|
||||||
|
|
||||||
|
|
||||||
def run(coro):
|
def run(coro):
|
||||||
|
@ -2,8 +2,8 @@ from collections import namedtuple
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja.utils import Markup
|
from jinja2.utils import Markup
|
||||||
|
|
||||||
|
|
||||||
async def make_aiter(iter):
|
async def make_aiter(iter):
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja.bccache import Bucket
|
from jinja2.bccache import Bucket
|
||||||
from jinja.bccache import FileSystemBytecodeCache
|
from jinja2.bccache import FileSystemBytecodeCache
|
||||||
from jinja.bccache import MemcachedBytecodeCache
|
from jinja2.bccache import MemcachedBytecodeCache
|
||||||
from jinja.exceptions import TemplateNotFound
|
from jinja2.exceptions import TemplateNotFound
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -53,7 +53,7 @@ class TestMemcachedBytecodeCache(object):
|
|||||||
b = Bucket(None, "key", "")
|
b = Bucket(None, "key", "")
|
||||||
b.code = "code"
|
b.code = "code"
|
||||||
m.dump_bytecode(b)
|
m.dump_bytecode(b)
|
||||||
assert memcached.key == "jinja/bytecode/key"
|
assert memcached.key == "jinja2/bytecode/key"
|
||||||
|
|
||||||
b = Bucket(None, "key", "")
|
b = Bucket(None, "key", "")
|
||||||
m.load_bytecode(b)
|
m.load_bytecode(b)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import DictLoader
|
from jinja2 import DictLoader
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import TemplateRuntimeError
|
from jinja2 import TemplateRuntimeError
|
||||||
from jinja import TemplateSyntaxError
|
from jinja2 import TemplateSyntaxError
|
||||||
from jinja import UndefinedError
|
from jinja2 import UndefinedError
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -5,10 +5,10 @@ from traceback import format_exception
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import ChoiceLoader
|
from jinja2 import ChoiceLoader
|
||||||
from jinja import DictLoader
|
from jinja2 import DictLoader
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import TemplateSyntaxError
|
from jinja2 import TemplateSyntaxError
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -55,7 +55,7 @@ ZeroDivisionError: (int(eger)? )?division (or modulo )?by zero
|
|||||||
"""(?sm)
|
"""(?sm)
|
||||||
File ".*?syntaxerror.html", line 4, in (template|<module>)
|
File ".*?syntaxerror.html", line 4, in (template|<module>)
|
||||||
\\{% endif %\\}.*?
|
\\{% endif %\\}.*?
|
||||||
(jinja\\.exceptions\\.)?TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja \
|
(jinja2\\.exceptions\\.)?TemplateSyntaxError: Encountered unknown tag 'endif'. Jinja \
|
||||||
was looking for the following tags: 'endfor' or 'else'. The innermost block that needs \
|
was looking for the following tags: 'endfor' or 'else'. The innermost block that needs \
|
||||||
to be closed is 'for'.
|
to be closed is 'for'.
|
||||||
""",
|
""",
|
||||||
@ -70,7 +70,7 @@ to be closed is 'for'.
|
|||||||
r"""
|
r"""
|
||||||
File ".*debug.pyc?", line \d+, in test
|
File ".*debug.pyc?", line \d+, in test
|
||||||
raise TemplateSyntaxError\("wtf", 42\)
|
raise TemplateSyntaxError\("wtf", 42\)
|
||||||
(jinja\.exceptions\.)?TemplateSyntaxError: wtf
|
(jinja2\.exceptions\.)?TemplateSyntaxError: wtf
|
||||||
line 42""",
|
line 42""",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -97,8 +97,8 @@ to be closed is 'for'.
|
|||||||
assert exc_info.value.source is not None
|
assert exc_info.value.source is not None
|
||||||
|
|
||||||
def test_local_extraction(self):
|
def test_local_extraction(self):
|
||||||
from jinja.debug import get_template_locals
|
from jinja2.debug import get_template_locals
|
||||||
from jinja.runtime import missing
|
from jinja2.runtime import missing
|
||||||
|
|
||||||
locals = get_template_locals(
|
locals = get_template_locals(
|
||||||
{
|
{
|
||||||
|
@ -3,17 +3,17 @@ import re
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import contextfunction
|
from jinja2 import contextfunction
|
||||||
from jinja import DictLoader
|
from jinja2 import DictLoader
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import nodes
|
from jinja2 import nodes
|
||||||
from jinja._compat import BytesIO
|
from jinja2._compat import BytesIO
|
||||||
from jinja._compat import itervalues
|
from jinja2._compat import itervalues
|
||||||
from jinja._compat import text_type
|
from jinja2._compat import text_type
|
||||||
from jinja.exceptions import TemplateAssertionError
|
from jinja2.exceptions import TemplateAssertionError
|
||||||
from jinja.ext import Extension
|
from jinja2.ext import Extension
|
||||||
from jinja.lexer import count_newlines
|
from jinja2.lexer import count_newlines
|
||||||
from jinja.lexer import Token
|
from jinja2.lexer import Token
|
||||||
|
|
||||||
importable_object = 23
|
importable_object = 23
|
||||||
|
|
||||||
@ -80,16 +80,18 @@ def ngettext(context, s, p, n):
|
|||||||
return languages.get(language, {}).get(s, s)
|
return languages.get(language, {}).get(s, s)
|
||||||
|
|
||||||
|
|
||||||
i18n_env = Environment(loader=DictLoader(i18n_templates), extensions=["jinja.ext.i18n"])
|
i18n_env = Environment(
|
||||||
|
loader=DictLoader(i18n_templates), extensions=["jinja2.ext.i18n"]
|
||||||
|
)
|
||||||
i18n_env.globals.update({"_": gettext, "gettext": gettext, "ngettext": ngettext})
|
i18n_env.globals.update({"_": gettext, "gettext": gettext, "ngettext": ngettext})
|
||||||
i18n_env_trimmed = Environment(extensions=["jinja.ext.i18n"])
|
i18n_env_trimmed = Environment(extensions=["jinja2.ext.i18n"])
|
||||||
i18n_env_trimmed.policies["ext.i18n.trimmed"] = True
|
i18n_env_trimmed.policies["ext.i18n.trimmed"] = True
|
||||||
i18n_env_trimmed.globals.update(
|
i18n_env_trimmed.globals.update(
|
||||||
{"_": gettext, "gettext": gettext, "ngettext": ngettext}
|
{"_": gettext, "gettext": gettext, "ngettext": ngettext}
|
||||||
)
|
)
|
||||||
|
|
||||||
newstyle_i18n_env = Environment(
|
newstyle_i18n_env = Environment(
|
||||||
loader=DictLoader(newstyle_i18n_templates), extensions=["jinja.ext.i18n"]
|
loader=DictLoader(newstyle_i18n_templates), extensions=["jinja2.ext.i18n"]
|
||||||
)
|
)
|
||||||
newstyle_i18n_env.install_gettext_callables(gettext, ngettext, newstyle=True)
|
newstyle_i18n_env.install_gettext_callables(gettext, ngettext, newstyle=True)
|
||||||
|
|
||||||
@ -169,12 +171,12 @@ class StreamFilterExtension(Extension):
|
|||||||
class TestExtensions(object):
|
class TestExtensions(object):
|
||||||
def test_extend_late(self):
|
def test_extend_late(self):
|
||||||
env = Environment()
|
env = Environment()
|
||||||
env.add_extension("jinja.ext.autoescape")
|
env.add_extension("jinja2.ext.autoescape")
|
||||||
t = env.from_string('{% autoescape true %}{{ "<test>" }}{% endautoescape %}')
|
t = env.from_string('{% autoescape true %}{{ "<test>" }}{% endautoescape %}')
|
||||||
assert t.render() == "<test>"
|
assert t.render() == "<test>"
|
||||||
|
|
||||||
def test_loop_controls(self):
|
def test_loop_controls(self):
|
||||||
env = Environment(extensions=["jinja.ext.loopcontrols"])
|
env = Environment(extensions=["jinja2.ext.loopcontrols"])
|
||||||
|
|
||||||
tmpl = env.from_string(
|
tmpl = env.from_string(
|
||||||
"""
|
"""
|
||||||
@ -195,7 +197,7 @@ class TestExtensions(object):
|
|||||||
assert tmpl.render() == "12"
|
assert tmpl.render() == "12"
|
||||||
|
|
||||||
def test_do(self):
|
def test_do(self):
|
||||||
env = Environment(extensions=["jinja.ext.do"])
|
env = Environment(extensions=["jinja2.ext.do"])
|
||||||
tmpl = env.from_string(
|
tmpl = env.from_string(
|
||||||
"""
|
"""
|
||||||
{%- set items = [] %}
|
{%- set items = [] %}
|
||||||
@ -257,7 +259,7 @@ class TestExtensions(object):
|
|||||||
assert ext[1].__class__ is T2
|
assert ext[1].__class__ is T2
|
||||||
|
|
||||||
def test_debug(self):
|
def test_debug(self):
|
||||||
env = Environment(extensions=["jinja.ext.debug"])
|
env = Environment(extensions=["jinja2.ext.debug"])
|
||||||
t = env.from_string("Hello\n{% debug %}\nGoodbye")
|
t = env.from_string("Hello\n{% debug %}\nGoodbye")
|
||||||
out = t.render()
|
out = t.render()
|
||||||
|
|
||||||
@ -337,7 +339,7 @@ class TestInternationalization(object):
|
|||||||
assert tmpl.render() == " hello\n world "
|
assert tmpl.render() == " hello\n world "
|
||||||
|
|
||||||
def test_extract(self):
|
def test_extract(self):
|
||||||
from jinja.ext import babel_extract
|
from jinja2.ext import babel_extract
|
||||||
|
|
||||||
source = BytesIO(
|
source = BytesIO(
|
||||||
"""
|
"""
|
||||||
@ -355,7 +357,7 @@ class TestInternationalization(object):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def test_extract_trimmed(self):
|
def test_extract_trimmed(self):
|
||||||
from jinja.ext import babel_extract
|
from jinja2.ext import babel_extract
|
||||||
|
|
||||||
source = BytesIO(
|
source = BytesIO(
|
||||||
"""
|
"""
|
||||||
@ -374,7 +376,7 @@ class TestInternationalization(object):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def test_extract_trimmed_option(self):
|
def test_extract_trimmed_option(self):
|
||||||
from jinja.ext import babel_extract
|
from jinja2.ext import babel_extract
|
||||||
|
|
||||||
source = BytesIO(
|
source = BytesIO(
|
||||||
"""
|
"""
|
||||||
@ -394,7 +396,7 @@ class TestInternationalization(object):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def test_comment_extract(self):
|
def test_comment_extract(self):
|
||||||
from jinja.ext import babel_extract
|
from jinja2.ext import babel_extract
|
||||||
|
|
||||||
source = BytesIO(
|
source = BytesIO(
|
||||||
"""
|
"""
|
||||||
@ -483,7 +485,7 @@ class TestNewstyleInternationalization(object):
|
|||||||
assert tmpl.render(LANGUAGE="de", apples=5) == u"5 Äpfel"
|
assert tmpl.render(LANGUAGE="de", apples=5) == u"5 Äpfel"
|
||||||
|
|
||||||
def test_autoescape_support(self):
|
def test_autoescape_support(self):
|
||||||
env = Environment(extensions=["jinja.ext.autoescape", "jinja.ext.i18n"])
|
env = Environment(extensions=["jinja2.ext.autoescape", "jinja2.ext.i18n"])
|
||||||
env.install_gettext_callables(
|
env.install_gettext_callables(
|
||||||
lambda x: u"<strong>Wert: %(name)s</strong>",
|
lambda x: u"<strong>Wert: %(name)s</strong>",
|
||||||
lambda s, p, n: s,
|
lambda s, p, n: s,
|
||||||
@ -497,7 +499,7 @@ class TestNewstyleInternationalization(object):
|
|||||||
assert t.render(ae=False) == "<strong>Wert: <test></strong>"
|
assert t.render(ae=False) == "<strong>Wert: <test></strong>"
|
||||||
|
|
||||||
def test_autoescape_macros(self):
|
def test_autoescape_macros(self):
|
||||||
env = Environment(autoescape=False, extensions=["jinja.ext.autoescape"])
|
env = Environment(autoescape=False, extensions=["jinja2.ext.autoescape"])
|
||||||
template = (
|
template = (
|
||||||
"{% macro m() %}<html>{% endmacro %}"
|
"{% macro m() %}<html>{% endmacro %}"
|
||||||
"{% autoescape true %}{{ m() }}{% endautoescape %}"
|
"{% autoescape true %}{{ m() }}{% endautoescape %}"
|
||||||
@ -545,7 +547,7 @@ class TestNewstyleInternationalization(object):
|
|||||||
@pytest.mark.ext
|
@pytest.mark.ext
|
||||||
class TestAutoEscape(object):
|
class TestAutoEscape(object):
|
||||||
def test_scoped_setting(self):
|
def test_scoped_setting(self):
|
||||||
env = Environment(extensions=["jinja.ext.autoescape"], autoescape=True)
|
env = Environment(extensions=["jinja2.ext.autoescape"], autoescape=True)
|
||||||
tmpl = env.from_string(
|
tmpl = env.from_string(
|
||||||
"""
|
"""
|
||||||
{{ "<HelloWorld>" }}
|
{{ "<HelloWorld>" }}
|
||||||
@ -561,7 +563,7 @@ class TestAutoEscape(object):
|
|||||||
u"<HelloWorld>",
|
u"<HelloWorld>",
|
||||||
]
|
]
|
||||||
|
|
||||||
env = Environment(extensions=["jinja.ext.autoescape"], autoescape=False)
|
env = Environment(extensions=["jinja2.ext.autoescape"], autoescape=False)
|
||||||
tmpl = env.from_string(
|
tmpl = env.from_string(
|
||||||
"""
|
"""
|
||||||
{{ "<HelloWorld>" }}
|
{{ "<HelloWorld>" }}
|
||||||
@ -578,7 +580,7 @@ class TestAutoEscape(object):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def test_nonvolatile(self):
|
def test_nonvolatile(self):
|
||||||
env = Environment(extensions=["jinja.ext.autoescape"], autoescape=True)
|
env = Environment(extensions=["jinja2.ext.autoescape"], autoescape=True)
|
||||||
tmpl = env.from_string('{{ {"foo": "<test>"}|xmlattr|escape }}')
|
tmpl = env.from_string('{{ {"foo": "<test>"}|xmlattr|escape }}')
|
||||||
assert tmpl.render() == ' foo="<test>"'
|
assert tmpl.render() == ' foo="<test>"'
|
||||||
tmpl = env.from_string(
|
tmpl = env.from_string(
|
||||||
@ -588,7 +590,7 @@ class TestAutoEscape(object):
|
|||||||
assert tmpl.render() == " foo="&lt;test&gt;""
|
assert tmpl.render() == " foo="&lt;test&gt;""
|
||||||
|
|
||||||
def test_volatile(self):
|
def test_volatile(self):
|
||||||
env = Environment(extensions=["jinja.ext.autoescape"], autoescape=True)
|
env = Environment(extensions=["jinja2.ext.autoescape"], autoescape=True)
|
||||||
tmpl = env.from_string(
|
tmpl = env.from_string(
|
||||||
'{% autoescape foo %}{{ {"foo": "<test>"}'
|
'{% autoescape foo %}{{ {"foo": "<test>"}'
|
||||||
"|xmlattr|escape }}{% endautoescape %}"
|
"|xmlattr|escape }}{% endautoescape %}"
|
||||||
@ -597,7 +599,7 @@ class TestAutoEscape(object):
|
|||||||
assert tmpl.render(foo=True) == ' foo="<test>"'
|
assert tmpl.render(foo=True) == ' foo="<test>"'
|
||||||
|
|
||||||
def test_scoping(self):
|
def test_scoping(self):
|
||||||
env = Environment(extensions=["jinja.ext.autoescape"])
|
env = Environment(extensions=["jinja2.ext.autoescape"])
|
||||||
tmpl = env.from_string(
|
tmpl = env.from_string(
|
||||||
'{% autoescape true %}{% set x = "<x>" %}{{ x }}'
|
'{% autoescape true %}{% set x = "<x>" %}{{ x }}'
|
||||||
'{% endautoescape %}{{ x }}{{ "<y>" }}'
|
'{% endautoescape %}{{ x }}{{ "<y>" }}'
|
||||||
@ -605,7 +607,7 @@ class TestAutoEscape(object):
|
|||||||
assert tmpl.render(x=1) == "<x>1<y>"
|
assert tmpl.render(x=1) == "<x>1<y>"
|
||||||
|
|
||||||
def test_volatile_scoping(self):
|
def test_volatile_scoping(self):
|
||||||
env = Environment(extensions=["jinja.ext.autoescape"])
|
env = Environment(extensions=["jinja2.ext.autoescape"])
|
||||||
tmplsource = """
|
tmplsource = """
|
||||||
{% autoescape val %}
|
{% autoescape val %}
|
||||||
{% macro foo(x) %}
|
{% macro foo(x) %}
|
||||||
@ -621,11 +623,11 @@ class TestAutoEscape(object):
|
|||||||
|
|
||||||
# looking at the source we should see <testing> there in raw
|
# looking at the source we should see <testing> there in raw
|
||||||
# (and then escaped as well)
|
# (and then escaped as well)
|
||||||
env = Environment(extensions=["jinja.ext.autoescape"])
|
env = Environment(extensions=["jinja2.ext.autoescape"])
|
||||||
pysource = env.compile(tmplsource, raw=True)
|
pysource = env.compile(tmplsource, raw=True)
|
||||||
assert "<testing>\\n" in pysource
|
assert "<testing>\\n" in pysource
|
||||||
|
|
||||||
env = Environment(extensions=["jinja.ext.autoescape"], autoescape=True)
|
env = Environment(extensions=["jinja2.ext.autoescape"], autoescape=True)
|
||||||
pysource = env.compile(tmplsource, raw=True)
|
pysource = env.compile(tmplsource, raw=True)
|
||||||
assert "<testing>\\n" in pysource
|
assert "<testing>\\n" in pysource
|
||||||
|
|
||||||
|
@ -2,10 +2,10 @@ import sys
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import contextfilter
|
from jinja2 import contextfilter
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import Template
|
from jinja2 import Template
|
||||||
from jinja._compat import text_type
|
from jinja2._compat import text_type
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 5), reason="Requires 3.5 or later")
|
@pytest.mark.skipif(sys.version_info < (3, 5), reason="Requires 3.5 or later")
|
||||||
|
@ -4,10 +4,10 @@ from collections import namedtuple
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import Markup
|
from jinja2 import Markup
|
||||||
from jinja._compat import implements_to_string
|
from jinja2._compat import implements_to_string
|
||||||
from jinja._compat import text_type
|
from jinja2._compat import text_type
|
||||||
|
|
||||||
|
|
||||||
@implements_to_string
|
@implements_to_string
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from jinja import nodes
|
from jinja2 import nodes
|
||||||
from jinja.idtracking import symbols_for_node
|
from jinja2.idtracking import symbols_for_node
|
||||||
|
|
||||||
|
|
||||||
def test_basics():
|
def test_basics():
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import DictLoader
|
from jinja2 import DictLoader
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja.exceptions import TemplateNotFound
|
from jinja2.exceptions import TemplateNotFound
|
||||||
from jinja.exceptions import TemplatesNotFound
|
from jinja2.exceptions import TemplatesNotFound
|
||||||
from jinja.exceptions import TemplateSyntaxError
|
from jinja2.exceptions import TemplateSyntaxError
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import DictLoader
|
from jinja2 import DictLoader
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import TemplateRuntimeError
|
from jinja2 import TemplateRuntimeError
|
||||||
|
|
||||||
LAYOUTTEMPLATE = """\
|
LAYOUTTEMPLATE = """\
|
||||||
|{% block block1 %}block 1 from layout{% endblock %}
|
|{% block block1 %}block 1 from layout{% endblock %}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import nodes
|
from jinja2 import nodes
|
||||||
from jinja import Template
|
from jinja2 import Template
|
||||||
from jinja import TemplateSyntaxError
|
from jinja2 import TemplateSyntaxError
|
||||||
from jinja import UndefinedError
|
from jinja2 import UndefinedError
|
||||||
from jinja._compat import iteritems
|
from jinja2._compat import iteritems
|
||||||
from jinja._compat import PY2
|
from jinja2._compat import PY2
|
||||||
from jinja._compat import text_type
|
from jinja2._compat import text_type
|
||||||
from jinja.lexer import Token
|
from jinja2.lexer import Token
|
||||||
from jinja.lexer import TOKEN_BLOCK_BEGIN
|
from jinja2.lexer import TOKEN_BLOCK_BEGIN
|
||||||
from jinja.lexer import TOKEN_BLOCK_END
|
from jinja2.lexer import TOKEN_BLOCK_END
|
||||||
from jinja.lexer import TOKEN_EOF
|
from jinja2.lexer import TOKEN_EOF
|
||||||
from jinja.lexer import TokenStream
|
from jinja2.lexer import TokenStream
|
||||||
|
|
||||||
|
|
||||||
# how does a string look like in jinja syntax?
|
# how does a string look like in jinja syntax?
|
||||||
@ -122,7 +122,7 @@ class TestLexer(object):
|
|||||||
assert tmpl.render() == pformat("foo") + "|" + pformat(u"bär")
|
assert tmpl.render() == pformat("foo") + "|" + pformat(u"bär")
|
||||||
|
|
||||||
def test_operators(self, env):
|
def test_operators(self, env):
|
||||||
from jinja.lexer import operators
|
from jinja2.lexer import operators
|
||||||
|
|
||||||
for test, expect in iteritems(operators):
|
for test, expect in iteritems(operators):
|
||||||
if test in "([{}])":
|
if test in "([{}])":
|
||||||
|
@ -8,13 +8,13 @@ import weakref
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import loaders
|
from jinja2 import loaders
|
||||||
from jinja import PackageLoader
|
from jinja2 import PackageLoader
|
||||||
from jinja._compat import PY2
|
from jinja2._compat import PY2
|
||||||
from jinja._compat import PYPY
|
from jinja2._compat import PYPY
|
||||||
from jinja.exceptions import TemplateNotFound
|
from jinja2.exceptions import TemplateNotFound
|
||||||
from jinja.loaders import split_template_path
|
from jinja2.loaders import split_template_path
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.loaders
|
@pytest.mark.loaders
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja._compat import text_type
|
from jinja2._compat import text_type
|
||||||
from jinja.exceptions import UndefinedError
|
from jinja2.exceptions import UndefinedError
|
||||||
from jinja.nativetypes import NativeEnvironment
|
from jinja2.nativetypes import NativeEnvironment
|
||||||
from jinja.nativetypes import NativeTemplate
|
from jinja2.nativetypes import NativeTemplate
|
||||||
from jinja.runtime import Undefined
|
from jinja2.runtime import Undefined
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -3,14 +3,14 @@ import sys
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import DictLoader
|
from jinja2 import DictLoader
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import PrefixLoader
|
from jinja2 import PrefixLoader
|
||||||
from jinja import Template
|
from jinja2 import Template
|
||||||
from jinja import TemplateAssertionError
|
from jinja2 import TemplateAssertionError
|
||||||
from jinja import TemplateNotFound
|
from jinja2 import TemplateNotFound
|
||||||
from jinja import TemplateSyntaxError
|
from jinja2 import TemplateSyntaxError
|
||||||
from jinja._compat import text_type
|
from jinja2._compat import text_type
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.regression
|
@pytest.mark.regression
|
||||||
@ -295,7 +295,7 @@ class TestBug(object):
|
|||||||
assert e.value.name == "foo/bar.html"
|
assert e.value.name == "foo/bar.html"
|
||||||
|
|
||||||
def test_contextfunction_callable_classes(self, env):
|
def test_contextfunction_callable_classes(self, env):
|
||||||
from jinja.utils import contextfunction
|
from jinja2.utils import contextfunction
|
||||||
|
|
||||||
class CallableClass(object):
|
class CallableClass(object):
|
||||||
@contextfunction
|
@contextfunction
|
||||||
@ -369,7 +369,7 @@ class TestBug(object):
|
|||||||
|
|
||||||
def test_macro_escaping(self):
|
def test_macro_escaping(self):
|
||||||
env = Environment(
|
env = Environment(
|
||||||
autoescape=lambda x: False, extensions=["jinja.ext.autoescape"]
|
autoescape=lambda x: False, extensions=["jinja2.ext.autoescape"]
|
||||||
)
|
)
|
||||||
template = "{% macro m() %}<html>{% endmacro %}"
|
template = "{% macro m() %}<html>{% endmacro %}"
|
||||||
template += "{% autoescape true %}{{ m() }}{% endautoescape %}"
|
template += "{% autoescape true %}{{ m() }}{% endautoescape %}"
|
||||||
@ -577,7 +577,7 @@ class TestBug(object):
|
|||||||
assert env.get_template("main").render() == "123"
|
assert env.get_template("main").render() == "123"
|
||||||
|
|
||||||
def test_grouper_repr(self):
|
def test_grouper_repr(self):
|
||||||
from jinja.filters import _GroupTuple
|
from jinja2.filters import _GroupTuple
|
||||||
|
|
||||||
t = _GroupTuple("foo", [1, 2])
|
t = _GroupTuple("foo", [1, 2])
|
||||||
assert t.grouper == "foo"
|
assert t.grouper == "foo"
|
||||||
@ -586,7 +586,7 @@ class TestBug(object):
|
|||||||
assert str(t) == "('foo', [1, 2])"
|
assert str(t) == "('foo', [1, 2])"
|
||||||
|
|
||||||
def test_custom_context(self, env):
|
def test_custom_context(self, env):
|
||||||
from jinja.runtime import Context
|
from jinja2.runtime import Context
|
||||||
|
|
||||||
class MyContext(Context):
|
class MyContext(Context):
|
||||||
pass
|
pass
|
||||||
@ -599,7 +599,7 @@ class TestBug(object):
|
|||||||
assert env.get_template("test").render(foobar="test") == "test"
|
assert env.get_template("test").render(foobar="test") == "test"
|
||||||
|
|
||||||
def test_legacy_custom_context(self, env):
|
def test_legacy_custom_context(self, env):
|
||||||
from jinja.runtime import Context, missing
|
from jinja2.runtime import Context, missing
|
||||||
|
|
||||||
class MyContext(Context):
|
class MyContext(Context):
|
||||||
def resolve(self, name):
|
def resolve(self, name):
|
||||||
@ -620,7 +620,7 @@ class TestBug(object):
|
|||||||
assert tmpl.render(values=[]) == "0"
|
assert tmpl.render(values=[]) == "0"
|
||||||
|
|
||||||
def test_markup_and_chainable_undefined(self):
|
def test_markup_and_chainable_undefined(self):
|
||||||
from jinja import Markup
|
from jinja2 import Markup
|
||||||
from jinja.runtime import ChainableUndefined
|
from jinja2.runtime import ChainableUndefined
|
||||||
|
|
||||||
assert str(Markup(ChainableUndefined())) == ""
|
assert str(Markup(ChainableUndefined())) == ""
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from jinja import Template
|
from jinja2 import Template
|
||||||
from jinja.runtime import LoopContext
|
from jinja2.runtime import LoopContext
|
||||||
|
|
||||||
TEST_IDX_TEMPLATE_STR_1 = (
|
TEST_IDX_TEMPLATE_STR_1 = (
|
||||||
"[{% for i in lst|reverse %}(len={{ loop.length }},"
|
"[{% for i in lst|reverse %}(len={{ loop.length }},"
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import escape
|
from jinja2 import escape
|
||||||
from jinja import Markup
|
from jinja2 import Markup
|
||||||
from jinja._compat import text_type
|
from jinja2._compat import text_type
|
||||||
from jinja.exceptions import SecurityError
|
from jinja2.exceptions import SecurityError
|
||||||
from jinja.exceptions import TemplateRuntimeError
|
from jinja2.exceptions import TemplateRuntimeError
|
||||||
from jinja.exceptions import TemplateSyntaxError
|
from jinja2.exceptions import TemplateSyntaxError
|
||||||
from jinja.nodes import EvalContext
|
from jinja2.nodes import EvalContext
|
||||||
from jinja.sandbox import ImmutableSandboxedEnvironment
|
from jinja2.sandbox import ImmutableSandboxedEnvironment
|
||||||
from jinja.sandbox import SandboxedEnvironment
|
from jinja2.sandbox import SandboxedEnvironment
|
||||||
from jinja.sandbox import unsafe
|
from jinja2.sandbox import unsafe
|
||||||
|
|
||||||
|
|
||||||
class PrivateStuff(object):
|
class PrivateStuff(object):
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jinja import Environment
|
from jinja2 import Environment
|
||||||
from jinja import Markup
|
from jinja2 import Markup
|
||||||
|
|
||||||
|
|
||||||
class MyDict(dict):
|
class MyDict(dict):
|
||||||
|
@ -7,15 +7,15 @@ from copy import copy as shallow_copy
|
|||||||
import pytest
|
import pytest
|
||||||
from markupsafe import Markup
|
from markupsafe import Markup
|
||||||
|
|
||||||
from jinja._compat import range_type
|
from jinja2._compat import range_type
|
||||||
from jinja._compat import string_types
|
from jinja2._compat import string_types
|
||||||
from jinja.utils import consume
|
from jinja2.utils import consume
|
||||||
from jinja.utils import generate_lorem_ipsum
|
from jinja2.utils import generate_lorem_ipsum
|
||||||
from jinja.utils import LRUCache
|
from jinja2.utils import LRUCache
|
||||||
from jinja.utils import missing
|
from jinja2.utils import missing
|
||||||
from jinja.utils import object_type_repr
|
from jinja2.utils import object_type_repr
|
||||||
from jinja.utils import select_autoescape
|
from jinja2.utils import select_autoescape
|
||||||
from jinja.utils import urlize
|
from jinja2.utils import urlize
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.utils
|
@pytest.mark.utils
|
||||||
|
Loading…
Reference in New Issue
Block a user