Django

Code

Show
Ignore:
Timestamp:
11/13/08 13:03:42 (2 months ago)
Author:
kmtracey
Message:

Fixed #9579 -- Properly handle apps running with (and specifically, loading templates from) a current working directory path that contains non-ASCII characters. Thanks for the report to gonzalodelgado and for advice on how to fix it to Daniel Pope.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/utils/_os.py

    r9161 r9411  
    1 from os.path import join, normcase, abspath, sep 
     1import os 
     2from os.path import join, normcase, normpath, abspath, isabs, sep 
    23from django.utils.encoding import force_unicode 
     4 
     5# Define our own abspath function that can handle joining  
     6# unicode paths to a current working directory that has non-ASCII 
     7# characters in it.  This isn't necessary on Windows since the  
     8# Windows version of abspath handles this correctly.  The Windows 
     9# abspath also handles drive letters differently than the pure  
     10# Python implementation, so it's best not to replace it. 
     11if os.name == 'nt': 
     12    abspathu = abspath 
     13else: 
     14    def abspathu(path): 
     15        """ 
     16        Version of os.path.abspath that uses the unicode representation 
     17        of the current working directory, thus avoiding a UnicodeDecodeError 
     18        in join when the cwd has non-ASCII characters. 
     19        """ 
     20        if not isabs(path): 
     21            path = join(os.getcwdu(), path) 
     22        return normpath(path) 
    323 
    424def safe_join(base, *paths): 
     
    1434    base = force_unicode(base) 
    1535    paths = [force_unicode(p) for p in paths] 
    16     final_path = normcase(abspath(join(base, *paths))) 
    17     base_path = normcase(abspath(base)) 
     36    final_path = normcase(abspathu(join(base, *paths))) 
     37    base_path = normcase(abspathu(base)) 
    1838    base_path_len = len(base_path) 
    1939    # Ensure final_path starts with base_path and that the next character after