summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPreston Timmons <prestontimmons@gmail.com>2015-04-24 14:35:30 -0500
committerPreston Timmons <prestontimmons@gmail.com>2015-05-06 17:33:47 -0500
commitd17a035132c4ddba51d57286b2185bc459f69067 (patch)
tree9f154a8e77fc81d79ae28c36ad1cb52865d51342
parentadff499e47d99f6b40307acc1ace95508e3c5910 (diff)
Moved engine-related exceptions to django.template.exceptions.
With the introduction of multiple template engines these exceptions are no longer DTL-specific. It makes more sense for them to be moved out of DTL-related modules.
-rw-r--r--django/template/__init__.py4
-rw-r--r--django/template/base.py32
-rw-r--r--django/template/defaultfilters.py3
-rw-r--r--django/template/defaulttags.py19
-rw-r--r--django/template/engine.py3
-rw-r--r--django/template/exceptions.py43
-rw-r--r--django/template/loader.py2
-rw-r--r--django/template/loader_tags.py7
-rw-r--r--django/template/loaders/base.py2
-rw-r--r--django/template/loaders/cached.py2
-rw-r--r--django/template/loaders/eggs.py2
-rw-r--r--django/template/loaders/filesystem.py2
-rw-r--r--django/template/loaders/locmem.py2
-rw-r--r--django/template/response.py12
-rw-r--r--tests/i18n/tests.py3
-rw-r--r--tests/view_tests/tests/test_debug.py2
16 files changed, 80 insertions, 60 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py
index 780dbc29fc..cd1bf167c8 100644
--- a/django/template/__init__.py
+++ b/django/template/__init__.py
@@ -54,9 +54,9 @@ __all__ = ('Engine', 'engines')
# Django Template Language
# Public exceptions
-from .base import (TemplateDoesNotExist, TemplateSyntaxError, # NOQA
- VariableDoesNotExist)
+from .base import VariableDoesNotExist # NOQA
from .context import ContextPopException # NOQA
+from .exceptions import TemplateDoesNotExist, TemplateSyntaxError # NOQA
# Template parts
from .base import (Context, Node, NodeList, Origin, RequestContext, # NOQA
diff --git a/django/template/base.py b/django/template/base.py
index 3f1e1c2d72..3fd02570c2 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -82,6 +82,8 @@ from django.utils.text import (
from django.utils.timezone import template_localtime
from django.utils.translation import pgettext_lazy, ugettext_lazy
+from .exceptions import TemplateSyntaxError
+
TOKEN_TEXT = 0
TOKEN_VAR = 1
TOKEN_BLOCK = 2
@@ -129,36 +131,6 @@ builtins = []
logger = logging.getLogger('django.template')
-class TemplateSyntaxError(Exception):
- pass
-
-
-class TemplateDoesNotExist(Exception):
- """
- The exception used by backends when a template does not exist. Accepts the
- following optional arguments:
-
- backend
- The template backend class used when raising this exception.
-
- tried
- A list of sources that were tried when finding the template. This
- is formatted as a list of tuples containing (origin, status), where
- origin is an Origin object and status is a string with the reason the
- template wasn't found.
-
- chain
- A list of intermediate TemplateDoesNotExist exceptions. This is used to
- encapsulate multiple exceptions when loading templates from multiple
- engines.
- """
- def __init__(self, msg, tried=None, backend=None, chain=None):
- self.backend = backend
- self.tried = tried or []
- self.chain = chain or []
- super(TemplateDoesNotExist, self).__init__(msg)
-
-
class TemplateEncodingError(Exception):
pass
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index a3a9004494..7073bfaf4f 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -9,7 +9,6 @@ from functools import wraps
from pprint import pformat
from django.conf import settings
-from django.template.base import Library, Variable, VariableDoesNotExist
from django.utils import formats, six
from django.utils.dateformat import format, time_format
from django.utils.deprecation import RemovedInDjango20Warning
@@ -26,6 +25,8 @@ from django.utils.text import (
from django.utils.timesince import timesince, timeuntil
from django.utils.translation import ugettext, ungettext
+from .base import Library, Variable, VariableDoesNotExist
+
register = Library()
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 60d6839ca5..df2de0f2ea 100644
--- a/django/template/defaulttags.py
+++ b/django/template/defaulttags.py
@@ -9,7 +9,14 @@ from datetime import datetime
from itertools import cycle as itertools_cycle, groupby
from django.conf import settings
-from django.template.base import (
+from django.utils import six, timezone
+from django.utils.deprecation import RemovedInDjango20Warning
+from django.utils.encoding import force_text, smart_text
+from django.utils.html import format_html
+from django.utils.lorem_ipsum import paragraphs, words
+from django.utils.safestring import mark_safe
+
+from .base import (
BLOCK_TAG_END, BLOCK_TAG_START, COMMENT_TAG_END, COMMENT_TAG_START,
SINGLE_BRACE_END, SINGLE_BRACE_START, VARIABLE_ATTRIBUTE_SEPARATOR,
VARIABLE_TAG_END, VARIABLE_TAG_START, Context, InvalidTemplateLibrary,
@@ -17,14 +24,8 @@ from django.template.base import (
VariableDoesNotExist, get_library, kwarg_re, render_value_in_context,
token_kwargs,
)
-from django.template.defaultfilters import date
-from django.template.smartif import IfParser, Literal
-from django.utils import six, timezone
-from django.utils.deprecation import RemovedInDjango20Warning
-from django.utils.encoding import force_text, smart_text
-from django.utils.html import format_html
-from django.utils.lorem_ipsum import paragraphs, words
-from django.utils.safestring import mark_safe
+from .defaultfilters import date
+from .smartif import IfParser, Literal
register = Library()
diff --git a/django/template/engine.py b/django/template/engine.py
index 90015dfacc..241759229b 100644
--- a/django/template/engine.py
+++ b/django/template/engine.py
@@ -6,8 +6,9 @@ from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.functional import cached_property
from django.utils.module_loading import import_string
-from .base import Context, Template, TemplateDoesNotExist
+from .base import Context, Template
from .context import _builtin_context_processors
+from .exceptions import TemplateDoesNotExist
_context_instance_undefined = object()
_dictionary_undefined = object()
diff --git a/django/template/exceptions.py b/django/template/exceptions.py
new file mode 100644
index 0000000000..08650fb97d
--- /dev/null
+++ b/django/template/exceptions.py
@@ -0,0 +1,43 @@
+"""
+This module contains generic exceptions used by template backends. Although,
+due to historical reasons, the Django template language also internally uses
+these exceptions, other exceptions specific to the DTL should not be added
+here.
+"""
+
+
+class TemplateDoesNotExist(Exception):
+ """
+ The exception used when a template does not exist. Accepts the following
+ optional arguments:
+
+ backend
+ The template backend class used when raising this exception.
+
+ tried
+ A list of sources that were tried when finding the template. This
+ is formatted as a list of tuples containing (origin, status), where
+ origin is an Origin object or duck type and status is a string with the
+ reason the template wasn't found.
+
+ chain
+ A list of intermediate TemplateDoesNotExist exceptions. This is used to
+ encapsulate multiple exceptions when loading templates from multiple
+ engines.
+ """
+ def __init__(self, msg, tried=None, backend=None, chain=None):
+ self.backend = backend
+ if tried is None:
+ tried = []
+ self.tried = tried
+ if chain is None:
+ chain = []
+ self.chain = chain
+ super(TemplateDoesNotExist, self).__init__(msg)
+
+
+class TemplateSyntaxError(Exception):
+ """
+ The exception used for syntax errors during parsing or rendering.
+ """
+ pass
diff --git a/django/template/loader.py b/django/template/loader.py
index 43146e42b6..123eb7167f 100644
--- a/django/template/loader.py
+++ b/django/template/loader.py
@@ -4,10 +4,10 @@ from django.utils.deprecation import RemovedInDjango20Warning
from . import engines
from .backends.django import DjangoTemplates
-from .base import TemplateDoesNotExist
from .engine import (
_context_instance_undefined, _dictionary_undefined, _dirs_undefined,
)
+from .exceptions import TemplateDoesNotExist
from .loaders import base
diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
index 3b846a4099..4c662168e9 100644
--- a/django/template/loader_tags.py
+++ b/django/template/loader_tags.py
@@ -1,11 +1,12 @@
from collections import defaultdict
-from django.template.base import (
+from django.utils import six
+from django.utils.safestring import mark_safe
+
+from .base import (
Library, Node, Template, TemplateSyntaxError, TextNode, Variable,
token_kwargs,
)
-from django.utils import six
-from django.utils.safestring import mark_safe
register = Library()
diff --git a/django/template/loaders/base.py b/django/template/loaders/base.py
index b848bc05ce..4c429f7883 100644
--- a/django/template/loaders/base.py
+++ b/django/template/loaders/base.py
@@ -1,7 +1,7 @@
import warnings
from inspect import getargspec
-from django.template.base import Origin, Template, TemplateDoesNotExist
+from django.template import Origin, Template, TemplateDoesNotExist
from django.utils.deprecation import RemovedInDjango21Warning
diff --git a/django/template/loaders/cached.py b/django/template/loaders/cached.py
index b543a83026..4c9aa3077b 100644
--- a/django/template/loaders/cached.py
+++ b/django/template/loaders/cached.py
@@ -7,7 +7,7 @@ import hashlib
import warnings
from inspect import getargspec
-from django.template.base import Origin, Template, TemplateDoesNotExist
+from django.template import Origin, Template, TemplateDoesNotExist
from django.utils.deprecation import RemovedInDjango21Warning
from django.utils.encoding import force_bytes
diff --git a/django/template/loaders/eggs.py b/django/template/loaders/eggs.py
index 9dc291e485..44caee45cd 100644
--- a/django/template/loaders/eggs.py
+++ b/django/template/loaders/eggs.py
@@ -4,7 +4,7 @@ from __future__ import unicode_literals
import warnings
from django.apps import apps
-from django.template.base import Origin, TemplateDoesNotExist
+from django.template import Origin, TemplateDoesNotExist
from django.utils import six
from django.utils.deprecation import RemovedInDjango21Warning
diff --git a/django/template/loaders/filesystem.py b/django/template/loaders/filesystem.py
index e1ed0ba5e0..e21b85ef10 100644
--- a/django/template/loaders/filesystem.py
+++ b/django/template/loaders/filesystem.py
@@ -7,7 +7,7 @@ import io
import warnings
from django.core.exceptions import SuspiciousFileOperation
-from django.template.base import Origin, TemplateDoesNotExist
+from django.template import Origin, TemplateDoesNotExist
from django.utils._os import safe_join
from django.utils.deprecation import RemovedInDjango21Warning
diff --git a/django/template/loaders/locmem.py b/django/template/loaders/locmem.py
index f0ef792b35..afb716db4b 100644
--- a/django/template/loaders/locmem.py
+++ b/django/template/loaders/locmem.py
@@ -4,7 +4,7 @@ Wrapper for loading templates from a plain Python dict.
import warnings
-from django.template.base import Origin, TemplateDoesNotExist
+from django.template import Origin, TemplateDoesNotExist
from django.utils.deprecation import RemovedInDjango21Warning
from .base import Loader as BaseLoader
diff --git a/django/template/response.py b/django/template/response.py
index 094907ed97..1346303701 100644
--- a/django/template/response.py
+++ b/django/template/response.py
@@ -1,12 +1,14 @@
import warnings
from django.http import HttpResponse
-from django.template import Context, RequestContext, Template, loader
-from django.template.backends.django import Template as BackendTemplate
-from django.template.context import _current_app_undefined
from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning
+from .backends.django import Template as BackendTemplate
+from .base import Template
+from .context import Context, RequestContext, _current_app_undefined
+from .loader import get_template, select_template
+
class ContentNotRenderedError(Exception):
pass
@@ -75,9 +77,9 @@ class SimpleTemplateResponse(HttpResponse):
def resolve_template(self, template):
"Accepts a template object, path-to-template or list of paths"
if isinstance(template, (list, tuple)):
- return loader.select_template(template, using=self.using)
+ return select_template(template, using=self.using)
elif isinstance(template, six.string_types):
- return loader.get_template(template, using=self.using)
+ return get_template(template, using=self.using)
else:
return template
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
index 0be38f27b8..751419ffcb 100644
--- a/tests/i18n/tests.py
+++ b/tests/i18n/tests.py
@@ -13,8 +13,7 @@ from unittest import skipUnless
from django import forms
from django.conf import settings
-from django.template import Context, Template
-from django.template.base import TemplateSyntaxError
+from django.template import Context, Template, TemplateSyntaxError
from django.test import RequestFactory, TestCase, override_settings
from django.utils import six, translation
from django.utils._os import upath
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index ca852f0f0d..17c4f6e359 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -14,7 +14,7 @@ from unittest import skipIf
from django.core import mail
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.urlresolvers import reverse
-from django.template.base import TemplateDoesNotExist
+from django.template import TemplateDoesNotExist
from django.test import RequestFactory, TestCase, override_settings
from django.test.utils import LoggingCaptureMixin
from django.utils import six