aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2020-01-26 21:12:52 -0800
committerDavid Lord <davidism@gmail.com>2020-01-26 21:12:52 -0800
commit4a59ac9514d2ec3cfd8a38780ce81a250e31b692 (patch)
treefbf137fd6a5c333ced32436e33b614b1fb722a93 /src
parent4ec93a454b9b0a95f3772d56ebdac25702268f68 (diff)
downloadjinja-4a59ac9514d2ec3cfd8a38780ce81a250e31b692.tar.gz
Revert "rename imports to jinja"
This reverts commit 1167525b73863119f8bbec03ddb9d35eacff4bef.
Diffstat (limited to 'src')
-rw-r--r--src/jinja/bccache.py39
-rw-r--r--src/jinja/compiler.py4
-rw-r--r--src/jinja/environment.py12
-rw-r--r--src/jinja/ext.py14
-rw-r--r--src/jinja/filters.py6
-rw-r--r--src/jinja/lexer.py2
-rw-r--r--src/jinja/loaders.py4
-rw-r--r--src/jinja/meta.py4
-rw-r--r--src/jinja/nodes.py10
-rw-r--r--src/jinja/parser.py4
-rw-r--r--src/jinja/runtime.py12
-rw-r--r--src/jinja/sandbox.py2
-rw-r--r--src/jinja/utils.py6
13 files changed, 57 insertions, 62 deletions
diff --git a/src/jinja/bccache.py b/src/jinja/bccache.py
index f3feefbb..6f897451 100644
--- a/src/jinja/bccache.py
+++ b/src/jinja/bccache.py
@@ -23,14 +23,17 @@ from ._compat import pickle
from ._compat import text_type
from .utils import open_if_exists
-bc_version = 4
-# Magic bytes to identify Jinja bytecode cache files. Contains the
-# Python major and minor version to avoid loading incompatible bytecode
-# if a project upgrades its Python version.
+bc_version = 3
+
+# magic version used to only change with new jinja versions. With 2.6
+# 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 = (
- b"jinja"
+ "j2".encode("ascii")
+ 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):
"""To implement your own bytecode cache you have to subclass this class
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::
@@ -179,20 +182,15 @@ class FileSystemBytecodeCache(BytecodeCache):
is created for the user in the system temp directory.
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.
>>> bcc = FileSystemBytecodeCache('/tmp/jinja_cache', '%s.cache')
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:
directory = self._get_default_cache_dir()
self.directory = directory
@@ -214,7 +212,7 @@ class FileSystemBytecodeCache(BytecodeCache):
if not hasattr(os, "getuid"):
_unsafe_dir()
- dirname = "_jinja-cache-%d" % os.getuid()
+ dirname = "_jinja2-cache-%d" % os.getuid()
actual_dir = os.path.join(tmpdir, dirname)
try:
@@ -317,18 +315,15 @@ class MemcachedBytecodeCache(BytecodeCache):
This bytecode cache does not support clearing of used items in the cache.
The clear method is a no-operation function.
- .. versionchanged:: 2.11
- The default prefix was renamed to ``jinja/bytecode/``.
-
- .. versionchanged:: 2.7
- Added support for ignoring memcache errors through the
- ``ignore_memcache_errors`` parameter.
+ .. versionadded:: 2.7
+ Added support for ignoring memcache errors through the
+ `ignore_memcache_errors` parameter.
"""
def __init__(
self,
client,
- prefix="jinja/bytecode/",
+ prefix="jinja2/bytecode/",
timeout=None,
ignore_memcache_errors=True,
):
diff --git a/src/jinja/compiler.py b/src/jinja/compiler.py
index 88b4988b..32dac88c 100644
--- a/src/jinja/compiler.py
+++ b/src/jinja/compiler.py
@@ -715,11 +715,11 @@ class CodeGenerator(NodeVisitor):
from .runtime import __all__ as exported
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:
self.writeline(
- "from jinja.asyncsupport import auto_await, "
+ "from jinja2.asyncsupport import auto_await, "
"auto_aiter, AsyncLoopContext"
)
diff --git a/src/jinja/environment.py b/src/jinja/environment.py
index 16f5958e..08c5e6a0 100644
--- a/src/jinja/environment.py
+++ b/src/jinja/environment.py
@@ -218,7 +218,7 @@ class Environment(object):
`autoescape`
If set to ``True`` the XML/HTML autoescaping feature is enabled by
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
return ``True`` or ``False`` depending on autoescape should be
enabled by default.
@@ -262,7 +262,7 @@ class Environment(object):
#: if this environment is sandboxed. Modifying this variable won't make
#: 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.
sandboxed = False
@@ -277,11 +277,11 @@ class Environment(object):
shared = False
#: 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
#: 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
def __init__(
@@ -566,7 +566,7 @@ class Environment(object):
def _tokenize(self, source, name, filename=None, state=None):
"""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)
stream = self.lexer.tokenize(source, name, filename, state)
@@ -1254,7 +1254,7 @@ class TemplateModule(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
to the template with an expression it wraps.
"""
diff --git a/src/jinja/ext.py b/src/jinja/ext.py
index 0d0b4fe1..01aab74a 100644
--- a/src/jinja/ext.py
+++ b/src/jinja/ext.py
@@ -93,10 +93,10 @@ class Extension(with_metaclass(ExtensionRegistry, object)):
return source
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
- :class:`~jinja.lexer.Token`\\s, but it doesn't have to return a
- :class:`~jinja.lexer.TokenStream`.
+ :class:`~jinja2.lexer.Token`\\s, but it doesn't have to return a
+ :class:`~jinja2.lexer.TokenStream`.
"""
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
):
"""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:
args = []
@@ -476,9 +476,9 @@ class DebugExtension(Extension):
.. 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',
..., 'urlencode', 'urlize', 'wordcount', 'wordwrap', 'xmlattr'],
'tests': ['!=', '<', '<=', '==', '>', '>=', 'callable', 'defined',
@@ -523,7 +523,7 @@ def extract_from_ast(node, gettext_functions=GETTEXT_FUNCTIONS, babel_style=True
This example explains the behavior:
- >>> from jinja import Environment
+ >>> from jinja2 import Environment
>>> env = Environment()
>>> node = env.parse('{{ (_("foo"), _(), ngettext("foo", "bar", 42)) }}')
>>> list(extract_from_ast(node))
diff --git a/src/jinja/filters.py b/src/jinja/filters.py
index d090266f..1af7ac88 100644
--- a/src/jinja/filters.py
+++ b/src/jinja/filters.py
@@ -438,10 +438,10 @@ def do_default(value, default_value=u"", boolean=False):
{{ ''|default('the string was empty', true) }}
.. versionchanged:: 2.11
- It's now possible to configure the :class:`~jinja.Environment` with
- :class:`~jinja.ChainableUndefined` to make the `default` filter work
+ It's now possible to configure the :class:`~jinja2.Environment` with
+ :class:`~jinja2.ChainableUndefined` to make the `default` filter work
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):
return default_value
diff --git a/src/jinja/lexer.py b/src/jinja/lexer.py
index e6621f18..a2b44e92 100644
--- a/src/jinja/lexer.py
+++ b/src/jinja/lexer.py
@@ -397,7 +397,7 @@ class TokenStream(object):
def expect(self, expr):
"""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):
expr = describe_token_expr(expr)
diff --git a/src/jinja/loaders.py b/src/jinja/loaders.py
index cc1b0aa4..ce5537a0 100644
--- a/src/jinja/loaders.py
+++ b/src/jinja/loaders.py
@@ -46,7 +46,7 @@ class BaseLoader(object):
A very basic example for a loader that looks up templates on the file
system could look like this::
- from jinja import BaseLoader, TemplateNotFound
+ from jinja2 import BaseLoader, TemplateNotFound
from os.path import join, exists, getmtime
class MyLoader(BaseLoader):
@@ -523,7 +523,7 @@ class ModuleLoader(BaseLoader):
has_source_access = False
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
# path given.
diff --git a/src/jinja/meta.py b/src/jinja/meta.py
index f37141d9..3795aace 100644
--- a/src/jinja/meta.py
+++ b/src/jinja/meta.py
@@ -32,7 +32,7 @@ def find_undeclared_variables(ast):
variables will be used depending on the path the execution takes at
runtime, all variables are returned.
- >>> from jinja import Environment, meta
+ >>> from jinja2 import Environment, meta
>>> env = Environment()
>>> ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')
>>> 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
yielded.
- >>> from jinja import Environment, meta
+ >>> from jinja2 import Environment, meta
>>> env = Environment()
>>> ast = env.parse('{% extends "layout.html" %}{% include helper %}')
>>> list(meta.find_referenced_templates(ast))
diff --git a/src/jinja/nodes.py b/src/jinja/nodes.py
index e0128d38..f0e9e032 100644
--- a/src/jinja/nodes.py
+++ b/src/jinja/nodes.py
@@ -937,7 +937,7 @@ class ExtensionAttribute(Expr):
The identifier is the identifier of the :class:`Extension`.
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")
@@ -956,7 +956,7 @@ class ImportedName(Expr):
class InternalName(Expr):
"""An internal name in the compiler. You cannot create these nodes
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
template and is not threated specially by the compiler.
"""
@@ -1002,7 +1002,7 @@ class MarkSafeIfAutoescape(Expr):
class ContextReference(Expr):
"""Returns the current template context. It can be used like a
: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
variable named `foo`::
@@ -1011,7 +1011,7 @@ class ContextReference(Expr):
Getattr(ContextReference(), 'name'))
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
as the first argument to a function.
"""
@@ -1072,7 +1072,7 @@ class EvalContextModifier(Stmt):
class ScopedEvalContextModifier(EvalContextModifier):
"""Modifies the eval context and reverts it later. Works exactly like
: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",)
diff --git a/src/jinja/parser.py b/src/jinja/parser.py
index 7bf3a294..d5881066 100644
--- a/src/jinja/parser.py
+++ b/src/jinja/parser.py
@@ -123,7 +123,7 @@ class Parser(object):
return False
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
rv = object.__new__(nodes.InternalName)
nodes.Node.__init__(rv, "fi%d" % self._last_identifier, lineno=lineno)
@@ -607,7 +607,7 @@ class Parser(object):
explicit_parentheses=False,
):
"""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
if no commas where found.
diff --git a/src/jinja/runtime.py b/src/jinja/runtime.py
index f6d58a61..d356b074 100644
--- a/src/jinja/runtime.py
+++ b/src/jinja/runtime.py
@@ -701,7 +701,7 @@ class Undefined(object):
>>> foo + 42
Traceback (most recent call last):
...
- jinja.exceptions.UndefinedError: 'foo' is undefined
+ jinja2.exceptions.UndefinedError: 'foo' is undefined
"""
__slots__ = (
@@ -926,7 +926,7 @@ class ChainableUndefined(Undefined):
>>> foo.bar['baz'] + 42
Traceback (most recent call last):
...
- jinja.exceptions.UndefinedError: 'foo' is undefined
+ jinja2.exceptions.UndefinedError: 'foo' is undefined
.. versionadded:: 2.11.0
"""
@@ -954,7 +954,7 @@ class DebugUndefined(Undefined):
>>> foo + 42
Traceback (most recent call last):
...
- jinja.exceptions.UndefinedError: 'foo' is undefined
+ jinja2.exceptions.UndefinedError: 'foo' is undefined
"""
__slots__ = ()
@@ -980,15 +980,15 @@ class StrictUndefined(Undefined):
>>> str(foo)
Traceback (most recent call last):
...
- jinja.exceptions.UndefinedError: 'foo' is undefined
+ jinja2.exceptions.UndefinedError: 'foo' is undefined
>>> not foo
Traceback (most recent call last):
...
- jinja.exceptions.UndefinedError: 'foo' is undefined
+ jinja2.exceptions.UndefinedError: 'foo' is undefined
>>> foo + 42
Traceback (most recent call last):
...
- jinja.exceptions.UndefinedError: 'foo' is undefined
+ jinja2.exceptions.UndefinedError: 'foo' is undefined
"""
__slots__ = ()
diff --git a/src/jinja/sandbox.py b/src/jinja/sandbox.py
index 28f4c8dd..af4a96e6 100644
--- a/src/jinja/sandbox.py
+++ b/src/jinja/sandbox.py
@@ -197,7 +197,7 @@ def is_internal_attribute(obj, attr):
python objects. This is useful if the environment method
: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")
True
>>> is_internal_attribute(str, "upper")
diff --git a/src/jinja/utils.py b/src/jinja/utils.py
index b88e24bd..e3285e8e 100644
--- a/src/jinja/utils.py
+++ b/src/jinja/utils.py
@@ -543,7 +543,7 @@ def select_autoescape(
If you want to enable it for all templates created from strings or
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(
enabled_extensions=('html', 'xml'),
default_for_string=True,
@@ -552,7 +552,7 @@ def select_autoescape(
Example configuration to turn it on at all times except if the template
ends with `.txt`::
- from jinja import Environment, select_autoescape
+ from jinja2 import Environment, select_autoescape
env = Environment(autoescape=select_autoescape(
disabled_extensions=('txt',),
default_for_string=True,
@@ -719,7 +719,7 @@ def soft_unicode(s):
from markupsafe import soft_unicode
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.",
DeprecationWarning,
stacklevel=2,