app/django/template/loaders/filesystem.py
changeset 323 ff1a9aa48cfd
parent 54 03e267d67478
equal deleted inserted replaced
322:6641e941ef1e 323:ff1a9aa48cfd
     5 from django.conf import settings
     5 from django.conf import settings
     6 from django.template import TemplateDoesNotExist
     6 from django.template import TemplateDoesNotExist
     7 from django.utils._os import safe_join
     7 from django.utils._os import safe_join
     8 
     8 
     9 def get_template_sources(template_name, template_dirs=None):
     9 def get_template_sources(template_name, template_dirs=None):
       
    10     """
       
    11     Returns the absolute paths to "template_name", when appended to each
       
    12     directory in "template_dirs". Any paths that don't lie inside one of the
       
    13     template dirs are excluded from the result set, for security reasons.
       
    14     """
    10     if not template_dirs:
    15     if not template_dirs:
    11         template_dirs = settings.TEMPLATE_DIRS
    16         template_dirs = settings.TEMPLATE_DIRS
    12     for template_dir in template_dirs:
    17     for template_dir in template_dirs:
    13         try:
    18         try:
    14             yield safe_join(template_dir, template_name)
    19             yield safe_join(template_dir, template_name)
       
    20         except UnicodeDecodeError:
       
    21             # The template dir name was a bytestring that wasn't valid UTF-8.
       
    22             raise
    15         except ValueError:
    23         except ValueError:
    16             # The joined path was located outside of template_dir.
    24             # The joined path was located outside of this particular
       
    25             # template_dir (it might be inside another one, so this isn't
       
    26             # fatal).
    17             pass
    27             pass
    18 
    28 
    19 def load_template_source(template_name, template_dirs=None):
    29 def load_template_source(template_name, template_dirs=None):
    20     tried = []
    30     tried = []
    21     for filepath in get_template_sources(template_name, template_dirs):
    31     for filepath in get_template_sources(template_name, template_dirs):