summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/basic/cycle.py4
-rw-r--r--examples/basic/debugger.py2
-rw-r--r--examples/basic/inheritance.py4
-rw-r--r--examples/basic/test.py3
-rw-r--r--examples/basic/test_filter_and_linestatements.py3
-rw-r--r--examples/basic/test_loop_filter.py2
-rw-r--r--examples/basic/translate.py1
-rw-r--r--examples/bench.py3
-rw-r--r--examples/rwbench/djangoext.py18
-rw-r--r--examples/rwbench/rwbench.py33
-rw-r--r--ext/django2jinja/django2jinja.py20
-rw-r--r--ext/djangojinja2.py10
-rw-r--r--ext/inlinegettext.py6
-rwxr-xr-xscripts/jinja2-debug.py5
-rw-r--r--scripts/make-release.py6
-rw-r--r--src/jinja2/__init__.py80
-rw-r--r--src/jinja2/_compat.py1
-rw-r--r--src/jinja2/asyncfilters.py5
-rw-r--r--src/jinja2/asyncsupport.py12
-rw-r--r--src/jinja2/bccache.py20
-rw-r--r--src/jinja2/compiler.py32
-rw-r--r--src/jinja2/constants.py2
-rw-r--r--src/jinja2/debug.py8
-rw-r--r--src/jinja2/defaults.py11
-rw-r--r--src/jinja2/environment.py74
-rw-r--r--src/jinja2/exceptions.py5
-rw-r--r--src/jinja2/ext.py38
-rw-r--r--src/jinja2/filters.py27
-rw-r--r--src/jinja2/idtracking.py5
-rw-r--r--src/jinja2/lexer.py9
-rw-r--r--src/jinja2/loaders.py15
-rw-r--r--src/jinja2/meta.py7
-rw-r--r--src/jinja2/nativetypes.py14
-rw-r--r--src/jinja2/nodes.py9
-rw-r--r--src/jinja2/optimizer.py4
-rw-r--r--src/jinja2/parser.py11
-rw-r--r--src/jinja2/runtime.py32
-rw-r--r--src/jinja2/sandbox.py15
-rw-r--r--src/jinja2/tests.py12
-rw-r--r--src/jinja2/utils.py7
-rw-r--r--src/jinja2/visitor.py2
-rw-r--r--tests/conftest.py5
-rw-r--r--tests/test_api.py22
-rw-r--r--tests/test_async.py12
-rw-r--r--tests/test_asyncfilters.py1
-rw-r--r--tests/test_bytecode_cache.py6
-rw-r--r--tests/test_core_tags.py8
-rw-r--r--tests/test_debug.py7
-rw-r--r--tests/test_ext.py13
-rw-r--r--tests/test_features.py5
-rw-r--r--tests/test_filters.py8
-rw-r--r--tests/test_imports.py8
-rw-r--r--tests/test_inheritance.py4
-rw-r--r--tests/test_lexnparse.py18
-rw-r--r--tests/test_loader.py2
-rw-r--r--tests/test_regression.py10
-rw-r--r--tests/test_security.py15
-rw-r--r--tests/test_tests.py3
-rw-r--r--tests/test_utils.py19
59 files changed, 460 insertions, 283 deletions
diff --git a/examples/basic/cycle.py b/examples/basic/cycle.py
index ecfd7b9..63d8a42 100644
--- a/examples/basic/cycle.py
+++ b/examples/basic/cycle.py
@@ -1,10 +1,8 @@
from __future__ import print_function
-from jinja2 import Environment
+from jinja2 import Environment
env = Environment(line_statement_prefix="#", variable_start_string="${", variable_end_string="}")
-
-
print(env.from_string("""\
<ul>
# for item in range(10)
diff --git a/examples/basic/debugger.py b/examples/basic/debugger.py
index 4c101ff..b74125b 100644
--- a/examples/basic/debugger.py
+++ b/examples/basic/debugger.py
@@ -1,8 +1,8 @@
from __future__ import print_function
+
from jinja2 import Environment
from jinja2.loaders import FileSystemLoader
env = Environment(loader=FileSystemLoader('templates'))
-
tmpl = env.get_template('broken.html')
print(tmpl.render(seq=[3, 2, 4, 5, 3, 2, 0, 2, 1]))
diff --git a/examples/basic/inheritance.py b/examples/basic/inheritance.py
index d5f0ae4..647f42c 100644
--- a/examples/basic/inheritance.py
+++ b/examples/basic/inheritance.py
@@ -1,13 +1,11 @@
from __future__ import print_function
+
from jinja2 import Environment
from jinja2.loaders import DictLoader
-
env = Environment(loader=DictLoader({
'a': '''[A[{% block body %}{% endblock %}]]''',
'b': '''{% extends 'a' %}{% block body %}[B]{% endblock %}''',
'c': '''{% extends 'b' %}{% block body %}###{{ super() }}###{% endblock %}'''
}))
-
-
print(env.get_template('c').render())
diff --git a/examples/basic/test.py b/examples/basic/test.py
index 4459726..04a6adc 100644
--- a/examples/basic/test.py
+++ b/examples/basic/test.py
@@ -1,4 +1,5 @@
from __future__ import print_function
+
from jinja2 import Environment
from jinja2.loaders import DictLoader
@@ -22,7 +23,5 @@ env = Environment(loader=DictLoader({
{% macro conspirate() %}23{% endmacro %}
'''
}))
-
-
tmpl = env.get_template("child.html")
print(tmpl.render())
diff --git a/examples/basic/test_filter_and_linestatements.py b/examples/basic/test_filter_and_linestatements.py
index 81da750..c18731c 100644
--- a/examples/basic/test_filter_and_linestatements.py
+++ b/examples/basic/test_filter_and_linestatements.py
@@ -1,6 +1,6 @@
from __future__ import print_function
-from jinja2 import Environment
+from jinja2 import Environment
env = Environment(line_statement_prefix='%', variable_start_string="${", variable_end_string="}")
tmpl = env.from_string("""\
@@ -22,5 +22,4 @@ tmpl = env.from_string("""\
% endfor
% endfilter
""")
-
print(tmpl.render(seq=range(10)))
diff --git a/examples/basic/test_loop_filter.py b/examples/basic/test_loop_filter.py
index 38a221d..d5b908b 100644
--- a/examples/basic/test_loop_filter.py
+++ b/examples/basic/test_loop_filter.py
@@ -1,4 +1,5 @@
from __future__ import print_function
+
from jinja2 import Environment
tmpl = Environment().from_string("""\
@@ -9,5 +10,4 @@ tmpl = Environment().from_string("""\
</ul>
if condition: {{ 1 if foo else 0 }}
""")
-
print(tmpl.render(foo=True))
diff --git a/examples/basic/translate.py b/examples/basic/translate.py
index 8d1970f..bbe445a 100644
--- a/examples/basic/translate.py
+++ b/examples/basic/translate.py
@@ -1,4 +1,5 @@
from __future__ import print_function
+
from jinja2 import Environment
env = Environment(extensions=['jinja2.ext.i18n'])
diff --git a/examples/bench.py b/examples/bench.py
index 0193cc1..7d988cd 100644
--- a/examples/bench.py
+++ b/examples/bench.py
@@ -3,9 +3,10 @@
that we get a picture of how fast Jinja is for a semi real world
template. If a template engine is not installed the test is skipped.\
"""
-import sys
import cgi
+import sys
from timeit import Timer
+
from jinja2 import Environment as JinjaEnvironment
context = {
diff --git a/examples/rwbench/djangoext.py b/examples/rwbench/djangoext.py
index 9e9fa6c..06897e5 100644
--- a/examples/rwbench/djangoext.py
+++ b/examples/rwbench/djangoext.py
@@ -1,7 +1,16 @@
# -*- coding: utf-8 -*-
-from rwbench import ROOT
from os.path import join
+
+from django import template as django_template_module
from django.conf import settings
+from django.template import Context as DjangoContext
+from django.template import loader as django_loader
+from django.template import Node
+from django.template import TokenParser
+from django.template import Variable
+from rwbench import dateformat
+from rwbench import ROOT
+
settings.configure(
TEMPLATE_DIRS=(join(ROOT, 'django'),),
TEMPLATE_LOADERS=(
@@ -10,19 +19,12 @@ settings.configure(
)),
)
)
-from django.template import loader as django_loader, Context as DjangoContext, \
- Node, NodeList, Variable, TokenParser
-from django import template as django_template_module
-from django.template import Library
-
# for django extensions. We monkey patch our extensions in so that
# we don't have to initialize a more complex django setup.
django_extensions = django_template_module.Library()
django_template_module.builtins.append(django_extensions)
-
-from rwbench import dateformat
django_extensions.filter(dateformat)
diff --git a/examples/rwbench/rwbench.py b/examples/rwbench/rwbench.py
index c8dc5f8..af5d40b 100644
--- a/examples/rwbench/rwbench.py
+++ b/examples/rwbench/rwbench.py
@@ -11,22 +11,32 @@
:license: BSD.
"""
from __future__ import print_function
+
import sys
-from os.path import join, dirname, abspath
+from datetime import datetime
+from os.path import abspath
+from os.path import dirname
+from os.path import join
+from pstats import Stats
+from random import choice
+from random import randrange
+from timeit import Timer
+
+from djangoext import django_loader
+from djangoext import DjangoContext
+from genshi.template import TemplateLoader as GenshiTemplateLoader
+from mako.lookup import TemplateLookup
+
+from jinja2 import Environment
+from jinja2 import FileSystemLoader
+from jinja2.utils import generate_lorem_ipsum
+
try:
from cProfile import Profile
except ImportError:
from profile import Profile
-from pstats import Stats
-ROOT = abspath(dirname(__file__))
-from random import choice, randrange
-from datetime import datetime
-from timeit import Timer
-from jinja2 import Environment, FileSystemLoader
-from jinja2.utils import generate_lorem_ipsum
-from mako.lookup import TemplateLookup
-from genshi.template import TemplateLoader as GenshiTemplateLoader
+ROOT = abspath(dirname(__file__))
def dateformat(x):
@@ -38,6 +48,7 @@ jinja_env.filters['dateformat'] = dateformat
mako_lookup = TemplateLookup(directories=[join(ROOT, 'mako')])
genshi_loader = GenshiTemplateLoader([join(ROOT, 'genshi')])
+
class Article(object):
def __init__(self, id):
@@ -70,7 +81,6 @@ navigation = [
context = dict(users=users, articles=articles, page_navigation=navigation)
-
jinja_template = jinja_env.get_template('index.html')
mako_template = mako_lookup.get_template('index.html')
genshi_template = genshi_loader.load('index.html')
@@ -83,7 +93,6 @@ def test_mako():
mako_template.render_unicode(**context)
-from djangoext import django_loader, DjangoContext
def test_django():
# not cached because django is not thread safe and does
# not cache by itself so it would be unfair to cache it here.
diff --git a/ext/django2jinja/django2jinja.py b/ext/django2jinja/django2jinja.py
index c462922..e9c19b2 100644
--- a/ext/django2jinja/django2jinja.py
+++ b/ext/django2jinja/django2jinja.py
@@ -69,17 +69,25 @@
:license: BSD.
"""
from __future__ import print_function
-import re
+
import os
+import re
import sys
-from jinja2.defaults import *
+
from django.conf import settings
-from django.template import defaulttags as core_tags, loader, TextNode, \
- FilterExpression, libraries, Variable, loader_tags, TOKEN_TEXT, \
- TOKEN_VAR
+from django.template import defaulttags as core_tags
+from django.template import FilterExpression
+from django.template import libraries
+from django.template import loader
+from django.template import loader_tags
+from django.template import TextNode
+from django.template import TOKEN_TEXT
+from django.template import TOKEN_VAR
+from django.template import Variable
from django.template.debug import DebugVariableNode as VariableNode
from django.templatetags import i18n as i18n_tags
-from StringIO import StringIO
+
+from jinja2.defaults import *
_node_handlers = {}
diff --git a/ext/djangojinja2.py b/ext/djangojinja2.py
index d32eadf..3c0c425 100644
--- a/ext/djangojinja2.py
+++ b/ext/djangojinja2.py
@@ -19,13 +19,15 @@
:license: BSD.
"""
from itertools import chain
+
from django.conf import settings
from django.http import HttpResponse
-from django.core.exceptions import ImproperlyConfigured
-from django.template.context import get_standard_processors
from django.template import TemplateDoesNotExist
-from jinja2 import Environment, FileSystemLoader, TemplateNotFound
-from jinja2.defaults import DEFAULT_NAMESPACE
+from django.template.context import get_standard_processors
+
+from jinja2 import Environment
+from jinja2 import FileSystemLoader
+from jinja2 import TemplateNotFound
# the environment is unconfigured until the first template is loaded.
diff --git a/ext/inlinegettext.py b/ext/inlinegettext.py
index 0a54e13..fd545b7 100644
--- a/ext/inlinegettext.py
+++ b/ext/inlinegettext.py
@@ -10,9 +10,11 @@
:license: BSD.
"""
import re
-from jinja2.ext import Extension
-from jinja2.lexer import Token, count_newlines
+
from jinja2.exceptions import TemplateSyntaxError
+from jinja2.ext import Extension
+from jinja2.lexer import count_newlines
+from jinja2.lexer import Token
_outside_re = re.compile(r'\\?(gettext|_)\(')
diff --git a/scripts/jinja2-debug.py b/scripts/jinja2-debug.py
index 13350db..4f04436 100755
--- a/scripts/jinja2-debug.py
+++ b/scripts/jinja2-debug.py
@@ -10,10 +10,13 @@
:license: BSD.
"""
from __future__ import print_function
+
import sys
-import jinja2
+
from werkzeug import script
+import jinja2
+
env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do',
'jinja2.ext.loopcontrols',
'jinja2.ext.with_',
diff --git a/scripts/make-release.py b/scripts/make-release.py
index 51c3700..0b158dd 100644
--- a/scripts/make-release.py
+++ b/scripts/make-release.py
@@ -15,8 +15,10 @@ from __future__ import print_function
import os
import re
import sys
-from datetime import date, datetime
-from subprocess import PIPE, Popen
+from datetime import date
+from datetime import datetime
+from subprocess import PIPE
+from subprocess import Popen
_date_strip_re = re.compile(r'(?<=\d)(st|nd|rd|th)')
diff --git a/src/jinja2/__init__.py b/src/jinja2/__init__.py
index 9c46e49..dcd2835 100644
--- a/src/jinja2/__init__.py
+++ b/src/jinja2/__init__.py
@@ -26,47 +26,41 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
-__docformat__ = 'restructuredtext en'
-__version__ = "2.11.0.dev0"
-
-# high level interface
-from jinja2.environment import Environment, Template
-
-# loaders
-from jinja2.loaders import BaseLoader, FileSystemLoader, PackageLoader, \
- DictLoader, FunctionLoader, PrefixLoader, ChoiceLoader, \
- ModuleLoader
-
-# bytecode caches
-from jinja2.bccache import BytecodeCache, FileSystemBytecodeCache, \
- MemcachedBytecodeCache
+from .bccache import BytecodeCache
+from .bccache import FileSystemBytecodeCache
+from .bccache import MemcachedBytecodeCache
+from .environment import Environment
+from .environment import Template
+from .exceptions import TemplateAssertionError
+from .exceptions import TemplateError
+from .exceptions import TemplateNotFound
+from .exceptions import TemplateRuntimeError
+from .exceptions import TemplatesNotFound
+from .exceptions import TemplateSyntaxError
+from .exceptions import UndefinedError
+from .filters import contextfilter
+from .filters import environmentfilter
+from .filters import evalcontextfilter
+from .loaders import BaseLoader
+from .loaders import ChoiceLoader
+from .loaders import DictLoader
+from .loaders import FileSystemLoader
+from .loaders import FunctionLoader
+from .loaders import ModuleLoader
+from .loaders import PackageLoader
+from .loaders import PrefixLoader
+from .runtime import ChainableUndefined
+from .runtime import DebugUndefined
+from .runtime import make_logging_undefined
+from .runtime import StrictUndefined
+from .runtime import Undefined
+from .utils import clear_caches
+from .utils import contextfunction
+from .utils import environmentfunction
+from .utils import escape
+from .utils import evalcontextfunction
+from .utils import is_undefined
+from .utils import Markup
+from .utils import select_autoescape
-# undefined types
-from jinja2.runtime import Undefined, ChainableUndefined, DebugUndefined, \
- StrictUndefined, make_logging_undefined
-
-# exceptions
-from jinja2.exceptions import TemplateError, UndefinedError, \
- TemplateNotFound, TemplatesNotFound, TemplateSyntaxError, \
- TemplateAssertionError, TemplateRuntimeError
-
-# decorators and public utilities
-from jinja2.filters import environmentfilter, contextfilter, \
- evalcontextfilter
-from jinja2.utils import Markup, escape, clear_caches, \
- environmentfunction, evalcontextfunction, contextfunction, \
- is_undefined, select_autoescape
-
-__all__ = [
- 'Environment', 'Template', 'BaseLoader', 'FileSystemLoader',
- 'PackageLoader', 'DictLoader', 'FunctionLoader', 'PrefixLoader',
- 'ChoiceLoader', 'BytecodeCache', 'FileSystemBytecodeCache',
- 'MemcachedBytecodeCache', 'Undefined', 'DebugUndefined',
- 'StrictUndefined', 'TemplateError', 'UndefinedError', 'TemplateNotFound',
- 'TemplatesNotFound', 'TemplateSyntaxError', 'TemplateAssertionError',
- 'TemplateRuntimeError',
- 'ModuleLoader', 'environmentfilter', 'contextfilter', 'Markup', 'escape',
- 'environmentfunction', 'contextfunction', 'clear_caches', 'is_undefined',
- 'evalcontextfilter', 'evalcontextfunction', 'make_logging_undefined',
- 'select_autoescape',
-]
+__version__ = "2.11.0.dev0"
diff --git a/src/jinja2/_compat.py b/src/jinja2/_compat.py
index 814d224..55d8e35 100644
--- a/src/jinja2/_compat.py
+++ b/src/jinja2/_compat.py
@@ -16,7 +16,6 @@ PY2 = sys.version_info[0] == 2
PYPY = hasattr(sys, 'pypy_translation_info')
_identity = lambda x: x
-
if not PY2:
unichr = chr
range_type = range
diff --git a/src/jinja2/asyncfilters.py b/src/jinja2/asyncfilters.py
index cf051dd..967dcb4 100644
--- a/src/jinja2/asyncfilters.py
+++ b/src/jinja2/asyncfilters.py
@@ -1,7 +1,8 @@
from functools import wraps
-from jinja2.asyncsupport import auto_aiter, auto_await
-from jinja2 import filters
+from . import filters
+from .asyncsupport import auto_aiter
+from .asyncsupport import auto_await
async def auto_to_seq(value):
diff --git a/src/jinja2/asyncsupport.py b/src/jinja2/asyncsupport.py
index d225962..f7da273 100644
--- a/src/jinja2/asyncsupport.py
+++ b/src/jinja2/asyncsupport.py
@@ -13,12 +13,12 @@ import asyncio
import inspect
from functools import update_wrapper
-from jinja2.environment import TemplateModule
-from jinja2.runtime import LoopContext
-from jinja2.utils import concat
-from jinja2.utils import internalcode
-from jinja2.utils import Markup
-from jinja2.utils import missing
+from .environment import TemplateModule
+from .runtime import LoopContext
+from .utils import concat
+from .utils import internalcode
+from .utils import Markup
+from .utils import missing
async def concat_async(async_gen):
diff --git a/src/jinja2/bccache.py b/src/jinja2/bccache.py
index 1a7b5bf..6466df6 100644
--- a/src/jinja2/bccache.py
+++ b/src/jinja2/bccache.py
@@ -14,18 +14,22 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD.
"""
-from os import path, listdir
-import os
-import sys
-import stat
import errno
+import fnmatch
import marshal
+import os
+import stat
+import sys
import tempfile
-import fnmatch
from hashlib import sha1
-from jinja2.utils import open_if_exists
-from jinja2._compat import BytesIO, pickle, PY2, text_type
-
+from os import listdir
+from os import path
+
+from ._compat import BytesIO
+from ._compat import pickle
+from ._compat import PY2
+from ._compat import text_type
+from .utils import open_if_exists
# marshal works better on 3.x, one hack less required
if not PY2:
diff --git a/src/jinja2/compiler.py b/src/jinja2/compiler.py
index addf71e..308042a 100644
--- a/src/jinja2/compiler.py
+++ b/src/jinja2/compiler.py
@@ -9,20 +9,30 @@
:license: BSD, see LICENSE for more details.
"""
from collections import namedtuple
+from functools import update_wrapper
from itertools import chain
from keyword import iskeyword as is_python_keyword
-from functools import update_wrapper
-from jinja2 import nodes
-from jinja2.nodes import EvalContext
-from jinja2.visitor import NodeVisitor
-from jinja2.optimizer import Optimizer
-from jinja2.exceptions import TemplateAssertionError
-from jinja2.utils import Markup, concat, escape
-from jinja2._compat import range_type, text_type, string_types, \
- iteritems, NativeStringIO, imap, izip
-from jinja2.idtracking import Symbols, VAR_LOAD_PARAMETER, \
- VAR_LOAD_RESOLVE, VAR_LOAD_ALIAS, VAR_LOAD_UNDEFINED
+from . import nodes
+from ._compat import imap
+from ._compat import iteritems
+from ._compat import izip
+from ._compat import NativeStringIO
+from ._compat import range_type
+from ._compat import string_types
+from ._compat import text_type
+from .exceptions import TemplateAssertionError
+from .idtracking import Symbols
+from .idtracking import VAR_LOAD_ALIAS
+from .idtracking import VAR_LOAD_PARAMETER
+from .idtracking import VAR_LOAD_RESOLVE
+from .idtracking import VAR_LOAD_UNDEFINED
+from .nodes import EvalContext
+from .optimizer import Optimizer
+from .utils import concat
+from .utils import escape
+from .utils import Markup
+from .visitor import NodeVisitor
operators = {
'eq': '==',
diff --git a/src/jinja2/constants.py b/src/jinja2/constants.py
index 11efd1e..8d6a6a7 100644
--- a/src/jinja2/constants.py
+++ b/src/jinja2/constants.py
@@ -8,8 +8,6 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
-
-
#: list of lorem ipsum words used by the lipsum() helper function
LOREM_IPSUM_WORDS = u'''\
a ac accumsan ad adipiscing aenean aliquam aliquet amet ante aptent arcu at
diff --git a/src/jinja2/debug.py b/src/jinja2/debug.py
index 4370b79..23e891d 100644
--- a/src/jinja2/debug.py
+++ b/src/jinja2/debug.py
@@ -1,10 +1,10 @@
import sys
from types import CodeType
-from jinja2 import TemplateSyntaxError
-from jinja2._compat import PYPY
-from jinja2.utils import internal_code
-from jinja2.utils import missing
+from . import TemplateSyntaxError
+from ._compat import PYPY
+from .utils import internal_code
+from .utils import missing
def rewrite_traceback_stack(source=None):
diff --git a/src/jinja2/defaults.py b/src/jinja2/defaults.py
index 7c93dec..135ef81 100644
--- a/src/jinja2/defaults.py
+++ b/src/jinja2/defaults.py
@@ -8,9 +8,11 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
-from jinja2._compat import range_type
-from jinja2.utils import generate_lorem_ipsum, Cycler, Joiner, Namespace
-
+from ._compat import range_type
+from .utils import Cycler
+from .utils import generate_lorem_ipsum
+from .utils import Joiner
+from .utils import Namespace
# defaults for the parser / lexer
BLOCK_START_STRING = '{%'
@@ -26,7 +28,6 @@ LSTRIP_BLOCKS = False
NEWLINE_SEQUENCE = '\n'
KEEP_TRAILING_NEWLINE = False
-
# default filters, tests and namespace
from jinja2.filters import FILTERS as DEFAULT_FILTERS
from jinja2.tests import TESTS as DEFAULT_TESTS
@@ -39,7 +40,6 @@ DEFAULT_NAMESPACE = {
'namespace': Namespace
}
-
# default policies
DEFAULT_POLICIES = {
'compiler.ascii_str': True,
@@ -51,6 +51,5 @@ DEFAULT_POLICIES = {
'ext.i18n.trimmed': False,
}
-
# export all constants
__all__ = tuple(x for x in locals().keys() if x.isupper())
diff --git a/src/jinja2/environment.py b/src/jinja2/environment.py
index 1209e9d..252d7eb 100644
--- a/src/jinja2/environment.py
+++ b/src/jinja2/environment.py
@@ -11,27 +11,59 @@
import os
import sys
import weakref
-from functools import reduce, partial
-from jinja2 import nodes
-from jinja2.defaults import BLOCK_START_STRING, \
- BLOCK_END_STRING, VARIABLE_START_STRING, VARIABLE_END_STRING, \
- COMMENT_START_STRING, COMMENT_END_STRING, LINE_STATEMENT_PREFIX, \
- LINE_COMMENT_PREFIX, TRIM_BLOCKS, NEWLINE_SEQUENCE, \
- DEFAULT_FILTERS, DEFAULT_TESTS, DEFAULT_NAMESPACE, \
- DEFAULT_POLICIES, KEEP_TRAILING_NEWLINE, LSTRIP_BLOCKS
-from jinja2.lexer import get_lexer, TokenStream
-from jinja2.parser import Parser
-from jinja2.nodes import EvalContext
-from jinja2.compiler import generate, CodeGenerator
-from jinja2.runtime import Undefined, new_context, Context
-from jinja2.exceptions import TemplateSyntaxError, TemplateNotFound, \
- TemplatesNotFound, TemplateRuntimeError, UndefinedError
-from jinja2.utils import import_string, LRUCache, Markup, missing, \
- concat, consume, internalcode, have_async_gen
-from jinja2._compat import imap, ifilter, string_types, iteritems, \
- text_type, reraise, implements_iterator, implements_to_string, \
- encode_filename, PY2, PYPY
-
+from functools import partial
+from functools import reduce
+
+from . import nodes
+from ._compat import encode_filename
+from ._compat import ifilter
+from ._compat import imap
+from ._compat import implements_iterator
+from ._compat import implements_to_string
+from ._compat import iteritems
+from ._compat import PY2
+from ._compat import PYPY
+from ._compat import reraise
+from ._compat import string_types
+from ._compat import text_type
+from .compiler import CodeGenerator
+from .compiler import generate
+from .defaults import BLOCK_END_STRING
+from .defaults import BLOCK_START_STRING
+from .defaults import COMMENT_END_STRING
+from .defaults import COMMENT_START_STRING
+from .defaults import DEFAULT_FILTERS
+from .defaults import DEFAULT_NAMESPACE
+from .defaults import DEFAULT_POLICIES
+from .defaults import DEFAULT_TESTS
+from .defaults import KEEP_TRAILING_NEWLINE
+from .defaults import LINE_COMMENT_PREFIX
+from .defaults import LINE_STATEMENT_PREFIX
+from .defaults import LSTRIP_BLOCKS
+from .defaults import NEWLINE_SEQUENCE
+from .defaults import TRIM_BLOCKS
+from .defaults import VARIABLE_END_STRING
+from .defaults import VARIABLE_START_STRING
+from .exceptions import TemplateNotFound
+from .exceptions import TemplateRuntimeError
+from .exceptions import TemplatesNotFound
+from .exceptions import TemplateSyntaxError
+from .exceptions import UndefinedError
+from .lexer import get_lexer
+from .lexer import TokenStream
+from .nodes import EvalContext
+from .parser import Parser
+from .runtime import Context
+from .runtime import new_context
+from .runtime import Undefined
+from .utils import concat
+from .utils import consume
+from .utils import have_async_gen
+from .utils import import_string
+from .utils import internalcode
+from .utils import LRUCache
+from .utils import Markup
+from .utils import missing
# for direct template usage we have up to ten living environments
_spontaneous_environments = LRUCache(10)
diff --git a/src/jinja2/exceptions.py b/src/jinja2/exceptions.py
index c01483b..6ceea30 100644
--- a/src/jinja2/exceptions.py
+++ b/src/jinja2/exceptions.py
@@ -8,7 +8,10 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
-from jinja2._compat import imap, text_type, PY2, implements_to_string
+from ._compat import imap
+from ._compat import implements_to_string
+from ._compat import PY2
+from ._compat import text_type
class TemplateError(Exception):
diff --git a/src/jinja2/ext.py b/src/jinja2/ext.py
index f04b37b..433277a 100644
--- a/src/jinja2/ext.py
+++ b/src/jinja2/ext.py
@@ -18,20 +18,30 @@ import pprint
import re
from sys import version_info
-from jinja2 import nodes
-from jinja2.defaults import BLOCK_START_STRING, \
- BLOCK_END_STRING, VARIABLE_START_STRING, VARIABLE_END_STRING, \
- COMMENT_START_STRING, COMMENT_END_STRING, LINE_STATEMENT_PREFIX, \
- LINE_COMMENT_PREFIX, TRIM_BLOCKS, NEWLINE_SEQUENCE, \
- KEEP_TRAILING_NEWLINE, LSTRIP_BLOCKS
-from jinja2.environment import Environment
-from jinja2.nodes import ContextReference
-from jinja2.runtime import concat
-from jinja2.exceptions import TemplateAssertionError, TemplateSyntaxError
-from jinja2.utils import contextfunction, import_string, Markup
-from jinja2._compat import with_metaclass, string_types, iteritems
-from markupsafe import escape
-
+from . import nodes
+from ._compat import iteritems
+from ._compat import string_types
+from ._compat import with_metaclass
+from .defaults import BLOCK_END_STRING
+from .defaults import BLOCK_START_STRING
+from .defaults import COMMENT_END_STRING
+from .defaults import COMMENT_START_STRING
+from .defaults import KEEP_TRAILING_NEWLINE
+from .defaults import LINE_COMMENT_PREFIX
+from .defaults import LINE_STATEMENT_PREFIX
+from .defaults import LSTRIP_BLOCKS
+from .defaults import NEWLINE_SEQUENCE
+from .defaults import TRIM_BLOCKS
+from .defaults import VARIABLE_END_STRING
+from .defaults import VARIABLE_START_STRING
+from .environment import Environment
+from .exceptions import TemplateAssertionError
+from .exceptions import TemplateSyntaxError
+from .nodes import ContextReference
+from .runtime import concat
+from .utils import contextfunction
+from .utils import import_string
+from .utils import Markup
# the only real useful gettext functions for a Jinja template. Note
# that ugettext must be assigned to gettext as Jinja doesn't support
diff --git a/src/jinja2/filters.py b/src/jinja2/filters.py
index b73f627..8bd389c 100644
--- a/src/jinja2/filters.py
+++ b/src/jinja2/filters.py
@@ -8,19 +8,28 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
-import re
import math
import random
+import re
import warnings
-
-from itertools import groupby, chain
from collections import namedtuple
-from jinja2.utils import Markup, escape, pformat, urlize, soft_unicode, \
- unicode_urlencode, htmlsafe_json_dumps
-from jinja2.runtime import Undefined
-from jinja2.exceptions import FilterArgumentError
-from jinja2._compat import imap, string_types, text_type, iteritems, abc
-
+from itertools import chain
+from itertools import groupby
+
+from ._compat import abc
+from ._compat import imap
+from ._compat import iteritems
+from ._compat import string_types
+from ._compat import text_type
+from .exceptions import FilterArgumentError
+from .runtime import Undefined
+from .utils import escape
+from .utils import htmlsafe_json_dumps
+from .utils import Markup
+from .utils import pformat
+from .utils import soft_unicode
+from .utils import unicode_urlencode
+from .utils import urlize
_word_re = re.compile(r'\w+', re.UNICODE)
_word_beginning_split_re = re.compile(r'([-\s\(\{\[\<]+)', re.UNICODE)
diff --git a/src/jinja2/idtracking.py b/src/jinja2/idtracking.py
index 491bfe0..069844c 100644
--- a/src/jinja2/idtracking.py
+++ b/src/jinja2/idtracking.py
@@ -1,6 +1,5 @@
-from jinja2.visitor import NodeVisitor
-from jinja2._compat import iteritems
-
+from ._compat import iteritems
+from .visitor import NodeVisitor
VAR_LOAD_PARAMETER = 'param'
VAR_LOAD_RESOLVE = 'resolve'
diff --git a/src/jinja2/lexer.py b/src/jinja2/lexer.py
index 910a931..cdd8427 100644
--- a/src/jinja2/lexer.py
+++ b/src/jinja2/lexer.py
@@ -19,9 +19,12 @@ from ast import literal_eval
from collections import deque
from operator import itemgetter
-from jinja2._compat import implements_iterator, intern, iteritems, text_type
-from jinja2.exceptions import TemplateSyntaxError
-from jinja2.utils import LRUCache
+from ._compat import implements_iterator
+from ._compat import intern
+from ._compat import iteritems
+from ._compat import text_type
+from .exceptions import TemplateSyntaxError
+from .utils import LRUCache
# cache for the lexers. Exists in order to be able to have multiple
# environments with the same lexer
diff --git a/src/jinja2/loaders.py b/src/jinja2/loaders.py
index cc269be..86049f7 100644
--- a/src/jinja2/loaders.py
+++ b/src/jinja2/loaders.py
@@ -12,13 +12,18 @@ import os
import pkgutil
import sys
import weakref
+from hashlib import sha1
from importlib import import_module
-from types import ModuleType
from os import path
-from hashlib import sha1
-from jinja2.exceptions import TemplateNotFound
-from jinja2.utils import open_if_exists, internalcode
-from jinja2._compat import string_types, iteritems, fspath, abc
+from types import ModuleType
+
+from ._compat import abc
+from ._compat import fspath
+from ._compat import iteritems
+from ._compat import string_types
+from .exceptions import TemplateNotFound
+from .utils import internalcode
+from .utils import open_if_exists
def split_template_path(template):
diff --git a/src/jinja2/meta.py b/src/jinja2/meta.py
index 0d25916..6a4208e 100644
--- a/src/jinja2/meta.py
+++ b/src/jinja2/meta.py
@@ -9,9 +9,10 @@
:copyright: (c) 2017 by the Jinja Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
-from jinja2 import nodes
-from jinja2.compiler import CodeGenerator
-from jinja2._compat import string_types, iteritems
+from . import nodes
+from ._compat import iteritems
+from ._compat import string_types
+from .compiler import CodeGenerator
class TrackingCodeGenerator(CodeGenerator):
diff --git a/src/jinja2/nativetypes.py b/src/jinja2/nativetypes.py
index e0de277..6b3e5f5 100644
--- a/src/jinja2/nativetypes.py
+++ b/src/jinja2/nativetypes.py
@@ -1,10 +1,14 @@
import types
from ast import literal_eval
-from itertools import islice, chain
-from jinja2 import nodes
-from jinja2._compat import text_type
-from jinja2.compiler import CodeGenerator, has_safe_repr
-from jinja2.environment import Environment, Template
+from itertools import chain
+from itertools import islice
+
+from . import nodes
+from ._compat import text_type
+from .compiler import CodeGenerator
+from .compiler import has_safe_repr
+from .environment import Environment
+from .environment import Template
def native_concat(nodes, preserve_quotes=True):
diff --git a/src/jinja2/nodes.py b/src/jinja2/nodes.py
index 00e0329..36d921d 100644
--- a/src/jinja2/nodes.py
+++ b/src/jinja2/nodes.py
@@ -12,13 +12,14 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
-import types
import operator
-
from collections import deque
-from jinja2.utils import Markup
-from jinja2._compat import izip, with_metaclass, text_type, PY2
+from ._compat import izip
+from ._compat import PY2
+from ._compat import text_type
+from ._compat import with_metaclass
+from .utils import Markup
_binop_to_func = {
'*': operator.mul,
diff --git a/src/jinja2/optimizer.py b/src/jinja2/optimizer.py
index 7065424..e262727 100644
--- a/src/jinja2/optimizer.py
+++ b/src/jinja2/optimizer.py
@@ -16,8 +16,8 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD.
"""
-from jinja2 import nodes
-from jinja2.visitor import NodeTransformer
+from . import nodes
+from .visitor import NodeTransformer
def optimize(node, environment):
diff --git a/src/jinja2/parser.py b/src/jinja2/parser.py
index 7403b08..3759761 100644
--- a/src/jinja2/parser.py
+++ b/src/jinja2/parser.py
@@ -8,11 +8,12 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
-from jinja2 import nodes
-from jinja2.exceptions import TemplateSyntaxError, TemplateAssertionError
-from jinja2.lexer import describe_token, describe_token_expr
-from jinja2._compat import imap
-
+from . import nodes
+from ._compat import imap
+from .exceptions import TemplateAssertionError
+from .exceptions import TemplateSyntaxError
+from .lexer import describe_token
+from .lexer import describe_token_expr
_statement_keywords = frozenset(['for', 'if', 'block', 'extends', 'print',
'macro', 'include', 'from', 'import',
diff --git a/src/jinja2/runtime.py b/src/jinja2/runtime.py
index 19ff838..7ee9927 100644
--- a/src/jinja2/runtime.py
+++ b/src/jinja2/runtime.py
@@ -9,19 +9,31 @@
:license: BSD.
"""
import sys
-
from itertools import chain
from types import MethodType
-from jinja2.nodes import EvalContext
-from jinja2.utils import Markup, soft_unicode, escape, missing, concat, \
- internalcode, object_type_repr, evalcontextfunction, Namespace
-from jinja2.exceptions import UndefinedError, TemplateRuntimeError, \
- TemplateNotFound
-from jinja2._compat import imap, text_type, iteritems, \
- implements_iterator, implements_to_string, string_types, PY2, \
- with_metaclass, abc
-
+from ._compat import abc
+from ._compat import imap
+from ._compat import implements_iterator
+from ._compat import implements_to_string
+from ._compat import iteritems
+from ._compat import PY2
+from ._compat import string_types
+from ._compat import text_type
+from ._compat import with_metaclass
+from .exceptions import TemplateNotFound
+from .exceptions import TemplateRuntimeError
+from .exceptions import UndefinedError
+from .nodes import EvalContext
+from .utils import concat
+from .utils import escape
+from .utils import evalcontextfunction
+from .utils import internalcode
+from .utils import Markup
+from .utils import missing
+from .utils import Namespace
+from .utils import object_type_repr
+from .utils import soft_unicode
# these variables are exported to the template runtime
__all__ = ['LoopContext', 'TemplateReference', 'Macro', 'Markup',
diff --git a/src/jinja2/sandbox.py b/src/jinja2/sandbox.py
index 6a1f286..a614c27 100644
--- a/src/jinja2/sandbox.py
+++ b/src/jinja2/sandbox.py
@@ -12,16 +12,19 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD.
"""
-import types
import operator
-from jinja2.environment import Environment
-from jinja2.exceptions import SecurityError
-from jinja2._compat import string_types, PY2, abc, range_type
-from jinja2.utils import Markup
+import types
+from string import Formatter
from markupsafe import EscapeFormatter
-from string import Formatter
+from ._compat import abc
+from ._compat import PY2
+from ._compat import range_type
+from ._compat import string_types
+from .environment import Environment
+from .exceptions import SecurityError
+from .utils import Markup
#: maximum number of items a range may produce
MAX_RANGE = 100000
diff --git a/src/jinja2/tests.py b/src/jinja2/tests.py
index aeec860..de0f105 100644
--- a/src/jinja2/tests.py
+++ b/src/jinja2/tests.py
@@ -8,16 +8,18 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
+import decimal
import operator
import re
-from jinja2.runtime import Undefined
-from jinja2._compat import text_type, string_types, integer_types, abc
-import decimal
+
+from ._compat import abc
+from ._compat import integer_types
+from ._compat import string_types
+from ._compat import text_type
+from .runtime import Undefined
number_re = re.compile(r'^-?\d+(\.\d+)?$')
regex_type = type(number_re)
-
-
test_callable = callable
diff --git a/src/jinja2/utils.py b/src/jinja2/utils.py
index 49501c7..de36eef 100644
--- a/src/jinja2/utils.py
+++ b/src/jinja2/utils.py
@@ -8,14 +8,17 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
+import json
import os
import re
-import json
import warnings
from collections import deque
from threading import Lock
-from jinja2._compat import text_type, string_types, url_quote, abc
+from ._compat import abc
+from ._compat import string_types
+from ._compat import text_type
+from ._compat import url_quote
_word_split_re = re.compile(r'(\s+)')
_punctuation_re = re.compile(
diff --git a/src/jinja2/visitor.py b/src/jinja2/visitor.py
index ba526df..2e03a6b 100644
--- a/src/jinja2/visitor.py
+++ b/src/jinja2/visitor.py
@@ -8,7 +8,7 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD.
"""
-from jinja2.nodes import Node
+from .nodes import Node
class NodeVisitor(object):
diff --git a/tests/conftest.py b/tests/conftest.py
index 0b6b353..c1c33c3 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -8,12 +8,13 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
-import pytest
import os
+import pytest
+
+from jinja2 import Environment
from jinja2 import loaders
from jinja2.utils import have_async_gen
-from jinja2 import Environment
def pytest_ignore_collect(path):
diff --git a/tests/test_api.py b/tests/test_api.py
index 6d31885..fff63ff 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -9,21 +9,29 @@
:license: BSD, see LICENSE for more details.
"""
import os
-import tempfile
import shutil
-from io import StringIO
+import tempfile
import pytest
-from jinja2 import Environment, Undefined, ChainableUndefined, \
- DebugUndefined, StrictUndefined, UndefinedError, meta, \
- is_undefined, Template, DictLoader, make_logging_undefined
+
+from jinja2 import ChainableUndefined
+from jinja2 import DebugUndefined
+from jinja2 import DictLoader
+from jinja2 import Environment
+from jinja2 import is_undefined
+from jinja2 import make_logging_undefined
+from jinja2 import meta
+from jinja2 import StrictUndefined
+from jinja2 import Template
from jinja2 import TemplatesNotFound
+from jinja2 import Undefined
+from jinja2 import UndefinedError
from jinja2.compiler import CodeGenerator
from jinja2.runtime import Context
-from jinja2.utils import Cycler
from jinja2.utils import contextfunction
-from jinja2.utils import evalcontextfunction
+from jinja2.utils import Cycler
from jinja2.utils import environmentfunction
+from jinja2.utils import evalcontextfunction
@pytest.mark.api
diff --git a/tests/test_async.py b/tests/test_async.py
index b71f094..2e0728d 100644
--- a/tests/test_async.py
+++ b/tests/test_async.py
@@ -1,10 +1,14 @@
-import pytest
import asyncio
-from jinja2 import Template, Environment, DictLoader
+import pytest
+
+from jinja2 import DictLoader
+from jinja2 import Environment
+from jinja2 import Template
from jinja2.asyncsupport import auto_aiter
-from jinja2.exceptions import TemplateNotFound, TemplatesNotFound, \
- UndefinedError
+from jinja2.exceptions import TemplateNotFound
+from jinja2.exceptions import TemplatesNotFound
+from jinja2.exceptions import UndefinedError
def run(coro):
diff --git a/tests/test_asyncfilters.py b/tests/test_asyncfilters.py
index 1e09b12..12b4e4f 100644
--- a/tests/test_asyncfilters.py
+++ b/tests/test_asyncfilters.py
@@ -1,4 +1,5 @@
import pytest
+
from jinja2 import Environment
from jinja2.utils import Markup
diff --git a/tests/test_bytecode_cache.py b/tests/test_bytecode_cache.py
index caef36b..a548ab2 100644
--- a/tests/test_bytecode_cache.py
+++ b/tests/test_bytecode_cache.py
@@ -8,12 +8,12 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
-
import pytest
from jinja2 import Environment
-from jinja2.bccache import Bucket, FileSystemBytecodeCache, \
- MemcachedBytecodeCache
+from jinja2.bccache import Bucket
+from jinja2.bccache import FileSystemBytecodeCache
+from jinja2.bccache import MemcachedBytecodeCache
from jinja2.exceptions import TemplateNotFound
diff --git a/tests/test_core_tags.py b/tests/test_core_tags.py
index 3b51e97..27981be 100644
--- a/tests/test_core_tags.py
+++ b/tests/test_core_tags.py
@@ -9,8 +9,12 @@
:license: BSD, see LICENSE for more details.
"""
import pytest
-from jinja2 import Environment, TemplateSyntaxError, TemplateRuntimeError, \
- UndefinedError, DictLoader
+
+from jinja2 import DictLoader
+from jinja2 import Environment
+from jinja2 import TemplateRuntimeError
+from jinja2 import TemplateSyntaxError
+from jinja2 import UndefinedError
@pytest.fixture
diff --git a/tests/test_debug.py b/tests/test_debug.py
index 459e908..78583de 100644
--- a/tests/test_debug.py
+++ b/tests/test_debug.py
@@ -8,16 +8,17 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
-import pytest
-
import pickle
import re
import sys
from traceback import format_exception
+import pytest
+
from jinja2 import ChoiceLoader
from jinja2 import DictLoader
-from jinja2 import Environment, TemplateSyntaxError
+from jinja2 import Environment
+from jinja2 import TemplateSyntaxError
@pytest.fixture
diff --git a/tests/test_ext.py b/tests/test_ext.py
index 7975271..6e8ab14 100644
--- a/tests/test_ext.py
+++ b/tests/test_ext.py
@@ -9,13 +9,20 @@
:license: BSD, see LICENSE for more details.
"""
import re
+
import pytest
-from jinja2 import Environment, DictLoader, contextfunction, nodes
+from jinja2 import contextfunction
+from jinja2 import DictLoader
+from jinja2 import Environment
+from jinja2 import nodes
+from jinja2._compat import BytesIO
+from jinja2._compat import itervalues
+from jinja2._compat import text_type
from jinja2.exceptions import TemplateAssertionError
from jinja2.ext import Extension
-from jinja2.lexer import Token, count_newlines
-from jinja2._compat import BytesIO, itervalues, text_type
+from jinja2.lexer import count_newlines
+from jinja2.lexer import Token
importable_object = 23
diff --git a/tests/test_features.py b/tests/test_features.py
index 3187890..d9ee4e5 100644
--- a/tests/test_features.py
+++ b/tests/test_features.py
@@ -1,7 +1,10 @@
import sys
+
import pytest
-from jinja2 import Template, Environment, contextfilter
+from jinja2 import contextfilter
+from jinja2 import Environment
+from jinja2 import Template
@pytest.mark.skipif(sys.version_info < (3, 5),
diff --git a/tests/test_filters.py b/tests/test_filters.py
index 9492663..b56e35b 100644
--- a/tests/test_filters.py
+++ b/tests/test_filters.py
@@ -9,9 +9,13 @@
:license: BSD, see LICENSE for more details.
"""
import random
+
import pytest
-from jinja2 import Markup, Environment
-from jinja2._compat import text_type, implements_to_string
+
+from jinja2 import Environment
+from jinja2 import Markup
+from jinja2._compat import implements_to_string
+from jinja2._compat import text_type
@implements_to_string
diff --git a/tests/test_imports.py b/tests/test_imports.py
index 0810e8a..2224fb8 100644
--- a/tests/test_imports.py
+++ b/tests/test_imports.py
@@ -10,9 +10,11 @@
"""
import pytest
-from jinja2 import Environment, DictLoader
-from jinja2.exceptions import TemplateNotFound, TemplatesNotFound, \
- TemplateSyntaxError
+from jinja2 import DictLoader
+from jinja2 import Environment
+from jinja2.exceptions import TemplateNotFound
+from jinja2.exceptions import TemplatesNotFound
+from jinja2.exceptions import TemplateSyntaxError
@pytest.fixture
diff --git a/tests/test_inheritance.py b/tests/test_inheritance.py
index f312164..32df340 100644
--- a/tests/test_inheritance.py
+++ b/tests/test_inheritance.py
@@ -10,7 +10,9 @@
"""
import pytest
-from jinja2 import Environment, DictLoader, TemplateError
+from jinja2 import DictLoader
+from jinja2 import Environment
+from jinja2 import TemplateError
from jinja2 import TemplateRuntimeError
LAYOUTTEMPLATE = '''\
diff --git a/tests/test_lexnparse.py b/tests/test_lexnparse.py
index b542282..a7ef46a 100644
--- a/tests/test_lexnparse.py
+++ b/tests/test_lexnparse.py
@@ -10,11 +10,19 @@
"""
import pytest
-from jinja2 import Environment, Template, TemplateSyntaxError, \
- UndefinedError, nodes
-from jinja2._compat import iteritems, text_type, PY2
-from jinja2.lexer import Token, TokenStream, TOKEN_EOF, \
- TOKEN_BLOCK_BEGIN, TOKEN_BLOCK_END
+from jinja2 import Environment
+from jinja2 import nodes
+from jinja2 import Template
+from jinja2 import TemplateSyntaxError
+from jinja2 import UndefinedError
+from jinja2._compat import iteritems
+from jinja2._compat import PY2
+from jinja2._compat import text_type
+from jinja2.lexer import Token
+from jinja2.lexer import TOKEN_BLOCK_BEGIN
+from jinja2.lexer import TOKEN_BLOCK_END
+from jinja2.lexer import TOKEN_EOF
+from jinja2.lexer import TokenStream
# how does a string look like in jinja syntax?
diff --git a/tests/test_loader.py b/tests/test_loader.py
index 62cfd68..68c1384 100644
--- a/tests/test_loader.py
+++ b/tests/test_loader.py
@@ -11,8 +11,8 @@
import os
import shutil
import sys
-import time
import tempfile
+import time
import weakref
import pytest
diff --git a/tests/test_regression.py b/tests/test_regression.py
index 4b228ef..df91785 100644
--- a/tests/test_regression.py
+++ b/tests/test_regression.py
@@ -9,10 +9,16 @@
:license: BSD, see LICENSE for more details.
"""
import sys
+
import pytest
-from jinja2 import Template, Environment, DictLoader, TemplateSyntaxError, \
- TemplateAssertionError, TemplateNotFound, PrefixLoader
+from jinja2 import DictLoader
+from jinja2 import Environment
+from jinja2 import PrefixLoader
+from jinja2 import Template
+from jinja2 import TemplateAssertionError
+from jinja2 import TemplateNotFound
+from jinja2 import TemplateSyntaxError
from jinja2._compat import text_type
diff --git a/tests/test_security.py b/tests/test_security.py
index 6b2743f..b37b655 100644
--- a/tests/test_security.py
+++ b/tests/test_security.py
@@ -11,13 +11,16 @@
import pytest
from jinja2 import Environment
-from jinja2.sandbox import SandboxedEnvironment, \
- ImmutableSandboxedEnvironment, unsafe
-from jinja2 import Markup, escape
-from jinja2.exceptions import SecurityError, TemplateSyntaxError, \
- TemplateRuntimeError
-from jinja2.nodes import EvalContext
+from jinja2 import escape
+from jinja2 import Markup
from jinja2._compat import text_type
+from jinja2.exceptions import SecurityError
+from jinja2.exceptions import TemplateRuntimeError
+from jinja2.exceptions import TemplateSyntaxError
+from jinja2.nodes import EvalContext
+from jinja2.sandbox import ImmutableSandboxedEnvironment
+from jinja2.sandbox import SandboxedEnvironment
+from jinja2.sandbox import unsafe
class PrivateStuff(object):
diff --git a/tests/test_tests.py b/tests/test_tests.py
index a596022..dd83efa 100644
--- a/tests/test_tests.py
+++ b/tests/test_tests.py
@@ -10,7 +10,8 @@
"""
import pytest
-from jinja2 import Markup, Environment
+from jinja2 import Environment
+from jinja2 import Markup
class MyDict(dict):
pass
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 7ff39f0..15b6c55 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -8,19 +8,24 @@
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
"""
-
-from collections import deque
-from copy import copy as shallow_copy
import pickle
import random
+from collections import deque
+from copy import copy as shallow_copy
import pytest
-
-from jinja2._compat import string_types, range_type
-from jinja2.utils import LRUCache, object_type_repr, urlize, \
- select_autoescape, generate_lorem_ipsum, missing, consume
from markupsafe import Markup
+from jinja2._compat import range_type
+from jinja2._compat import string_types
+from jinja2.utils import consume
+from jinja2.utils import generate_lorem_ipsum
+from jinja2.utils import LRUCache
+from jinja2.utils import missing
+from jinja2.utils import object_type_repr
+from jinja2.utils import select_autoescape
+from jinja2.utils import urlize
+
@pytest.mark.utils
@pytest.mark.lrucache