Loading django/template/engine.py +6 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,8 @@ class Engine(object): def __init__(self, dirs=None, app_dirs=False, allowed_include_roots=None, context_processors=None, loaders=None, string_if_invalid=''): loaders=None, string_if_invalid='', file_charset=None): if dirs is None: dirs = [] if allowed_include_roots is None: Loading @@ -33,6 +34,8 @@ class Engine(object): if app_dirs: raise ImproperlyConfigured( "APP_DIRS must not be set when LOADERS is defined.") if file_charset is None: file_charset = 'utf-8' self.dirs = dirs self.app_dirs = app_dirs Loading @@ -40,6 +43,7 @@ class Engine(object): self.context_processors = context_processors self.loaders = loaders self.string_if_invalid = string_if_invalid self.file_charset = file_charset @classmethod @lru_cache.lru_cache() Loading @@ -51,6 +55,7 @@ class Engine(object): context_processors=settings.TEMPLATE_CONTEXT_PROCESSORS, loaders=settings.TEMPLATE_LOADERS, string_if_invalid=settings.TEMPLATE_STRING_IF_INVALID, file_charset=settings.FILE_CHARSET, ) @cached_property Loading django/template/loaders/app_directories.py +1 −2 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ packages. import io from django.conf import settings from django.core.exceptions import SuspiciousFileOperation from django.template.base import TemplateDoesNotExist from django.template.utils import get_app_template_dirs Loading Loading @@ -36,7 +35,7 @@ class Loader(BaseLoader): def load_template_source(self, template_name, template_dirs=None): for filepath in self.get_template_sources(template_name, template_dirs): try: with io.open(filepath, encoding=settings.FILE_CHARSET) as fp: with io.open(filepath, encoding=self.engine.file_charset) as fp: return fp.read(), filepath except IOError: pass Loading django/template/loaders/eggs.py +1 −2 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ except ImportError: resource_string = None from django.apps import apps from django.conf import settings from django.template.base import TemplateDoesNotExist from django.utils import six Loading @@ -31,6 +30,6 @@ class Loader(BaseLoader): except Exception: continue if six.PY2: resource = resource.decode(settings.FILE_CHARSET) resource = resource.decode(self.engine.file_charset) return (resource, 'egg:%s:%s' % (app_config.name, pkg_name)) raise TemplateDoesNotExist(template_name) django/template/loaders/filesystem.py +4 −4 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ Wrapper for loading templates from the filesystem. import io from django.conf import settings from django.core.exceptions import SuspiciousFileOperation from django.template.base import TemplateDoesNotExist from django.utils._os import safe_join Loading @@ -22,7 +21,7 @@ class Loader(BaseLoader): template dirs are excluded from the result set, for security reasons. """ if not template_dirs: template_dirs = settings.TEMPLATE_DIRS template_dirs = self.engine.dirs for template_dir in template_dirs: try: yield safe_join(template_dir, template_name) Loading @@ -35,13 +34,14 @@ class Loader(BaseLoader): tried = [] for filepath in self.get_template_sources(template_name, template_dirs): try: with io.open(filepath, encoding=settings.FILE_CHARSET) as fp: with io.open(filepath, encoding=self.engine.file_charset) as fp: return fp.read(), filepath except IOError: tried.append(filepath) if tried: error_msg = "Tried %s" % tried else: error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory." error_msg = ("Your template directories configuration is empty. " "Change it to point to at least one template directory.") raise TemplateDoesNotExist(error_msg) load_template_source.is_usable = True django/test/signals.py +1 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,7 @@ def reset_default_template_engine(**kwargs): 'TEMPLATE_CONTEXT_PROCESSORS', 'TEMPLATE_LOADERS', 'TEMPLATE_STRING_IF_INVALID', 'FILE_CHARSET', }: from django.template.engine import Engine Engine.get_default.cache_clear() Loading Loading
django/template/engine.py +6 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,8 @@ class Engine(object): def __init__(self, dirs=None, app_dirs=False, allowed_include_roots=None, context_processors=None, loaders=None, string_if_invalid=''): loaders=None, string_if_invalid='', file_charset=None): if dirs is None: dirs = [] if allowed_include_roots is None: Loading @@ -33,6 +34,8 @@ class Engine(object): if app_dirs: raise ImproperlyConfigured( "APP_DIRS must not be set when LOADERS is defined.") if file_charset is None: file_charset = 'utf-8' self.dirs = dirs self.app_dirs = app_dirs Loading @@ -40,6 +43,7 @@ class Engine(object): self.context_processors = context_processors self.loaders = loaders self.string_if_invalid = string_if_invalid self.file_charset = file_charset @classmethod @lru_cache.lru_cache() Loading @@ -51,6 +55,7 @@ class Engine(object): context_processors=settings.TEMPLATE_CONTEXT_PROCESSORS, loaders=settings.TEMPLATE_LOADERS, string_if_invalid=settings.TEMPLATE_STRING_IF_INVALID, file_charset=settings.FILE_CHARSET, ) @cached_property Loading
django/template/loaders/app_directories.py +1 −2 Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ packages. import io from django.conf import settings from django.core.exceptions import SuspiciousFileOperation from django.template.base import TemplateDoesNotExist from django.template.utils import get_app_template_dirs Loading Loading @@ -36,7 +35,7 @@ class Loader(BaseLoader): def load_template_source(self, template_name, template_dirs=None): for filepath in self.get_template_sources(template_name, template_dirs): try: with io.open(filepath, encoding=settings.FILE_CHARSET) as fp: with io.open(filepath, encoding=self.engine.file_charset) as fp: return fp.read(), filepath except IOError: pass Loading
django/template/loaders/eggs.py +1 −2 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ except ImportError: resource_string = None from django.apps import apps from django.conf import settings from django.template.base import TemplateDoesNotExist from django.utils import six Loading @@ -31,6 +30,6 @@ class Loader(BaseLoader): except Exception: continue if six.PY2: resource = resource.decode(settings.FILE_CHARSET) resource = resource.decode(self.engine.file_charset) return (resource, 'egg:%s:%s' % (app_config.name, pkg_name)) raise TemplateDoesNotExist(template_name)
django/template/loaders/filesystem.py +4 −4 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ Wrapper for loading templates from the filesystem. import io from django.conf import settings from django.core.exceptions import SuspiciousFileOperation from django.template.base import TemplateDoesNotExist from django.utils._os import safe_join Loading @@ -22,7 +21,7 @@ class Loader(BaseLoader): template dirs are excluded from the result set, for security reasons. """ if not template_dirs: template_dirs = settings.TEMPLATE_DIRS template_dirs = self.engine.dirs for template_dir in template_dirs: try: yield safe_join(template_dir, template_name) Loading @@ -35,13 +34,14 @@ class Loader(BaseLoader): tried = [] for filepath in self.get_template_sources(template_name, template_dirs): try: with io.open(filepath, encoding=settings.FILE_CHARSET) as fp: with io.open(filepath, encoding=self.engine.file_charset) as fp: return fp.read(), filepath except IOError: tried.append(filepath) if tried: error_msg = "Tried %s" % tried else: error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory." error_msg = ("Your template directories configuration is empty. " "Change it to point to at least one template directory.") raise TemplateDoesNotExist(error_msg) load_template_source.is_usable = True
django/test/signals.py +1 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,7 @@ def reset_default_template_engine(**kwargs): 'TEMPLATE_CONTEXT_PROCESSORS', 'TEMPLATE_LOADERS', 'TEMPLATE_STRING_IF_INVALID', 'FILE_CHARSET', }: from django.template.engine import Engine Engine.get_default.cache_clear() Loading