Django

Code

Show
Ignore:
Timestamp:
10/06/08 01:34:54 (3 months ago)
Author:
mtredinnick
Message:

Added some better error reporting and path handling when creating template paths.

We now raise UnicodeDecodeError? for non-UTF-8 bytestrings (thanks to Daniel
Pope for diagnosing this was being swallowed by ValueError?) and allow UTF-8
bytestrings as template directories.

Refs #8965.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/template/loaders/app_directories.py

    r5750 r9161  
    3434 
    3535def get_template_sources(template_name, template_dirs=None): 
     36    """ 
     37    Returns the absolute paths to "template_name", when appended to each 
     38    directory in "template_dirs". Any paths that don't lie inside one of the 
     39    template dirs are excluded from the result set, for security reasons. 
     40    """ 
    3641    if not template_dirs: 
    3742        template_dirs = app_template_dirs 
     
    3944        try: 
    4045            yield safe_join(template_dir, template_name) 
     46        except UnicodeDecodeError: 
     47            # The template dir name was a bytestring that wasn't valid UTF-8. 
     48            raise 
    4149        except ValueError: 
    4250            # The joined path was located outside of template_dir. 
  • django/trunk/django/template/loaders/filesystem.py

    r5750 r9161  
    88 
    99def 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    """ 
    1015    if not template_dirs: 
    1116        template_dirs = settings.TEMPLATE_DIRS 
     
    1318        try: 
    1419            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 
    1523        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). 
    1727            pass 
    1828