mirror of
https://github.com/django/django.git
synced 2025-01-22 16:19:35 +00:00
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.
This commit is contained in:
parent
adff499e47
commit
d17a035132
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
43
django/template/exceptions.py
Normal file
43
django/template/exceptions.py
Normal file
@ -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
|
@ -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
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user