Django

Code

Changeset 5058

Show
Ignore:
Timestamp:
04/21/07 23:21:04 (1 year ago)
Author:
mtredinnick
Message:

unicode: Added FILE_CHARSET setting and use it to decode files read from disk.
Based on a patch from Ivan Sagalaev. Fixed #4021.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode/django/conf/global_settings.py

    r5054 r5058  
    9696DEFAULT_CHARSET = 'utf-8' 
    9797 
     98# Encoding of files read from disk (template and initial SQL files). 
     99FILE_CHARSET = 'utf-8' 
     100 
    98101# E-mail address that error messages come from. 
    99102SERVER_EMAIL = 'root@localhost' 
  • django/branches/unicode/django/core/management.py

    r5054 r5058  
    380380        if os.path.exists(sql_file): 
    381381            fp = open(sql_file, 'U') 
    382             for statement in statements.split(fp.read()): 
     382            for statement in statements.split(fp.read().decode(settings.FILE_CHARSET)): 
    383383                # Remove any comments from the file 
    384                 statement = re.sub(r"--.*[\n\Z]", "", statement) 
     384                statement = re.sub(ur"--.*[\n\Z]", "", statement) 
    385385                if statement.strip(): 
    386                     output.append(statement + ";") 
     386                    output.append(statement + u";") 
    387387            fp.close() 
    388388 
  • django/branches/unicode/django/template/loaders/app_directories.py

    r4265 r5058  
    3535    for filepath in get_template_sources(template_name, template_dirs): 
    3636        try: 
    37             return (open(filepath).read(), filepath) 
     37            return (open(filepath).read().decode(settings.FILE_CHARSET), filepath) 
    3838        except IOError: 
    3939            pass 
  • django/branches/unicode/django/template/loaders/eggs.py

    r4265 r5058  
    1919        for app in settings.INSTALLED_APPS: 
    2020            try: 
    21                 return (resource_string(app, pkg_name), 'egg:%s:%s ' % (app, pkg_name)) 
     21                return (resource_string(app, pkg_name), 'egg:%s:%s ' % (app, pkg_name)).decode(settings.FILE_CHARSET) 
    2222            except: 
    2323                pass 
  • django/branches/unicode/django/template/loaders/filesystem.py

    r3575 r5058  
    1515    for filepath in get_template_sources(template_name, template_dirs): 
    1616        try: 
    17             return (open(filepath).read(), filepath) 
     17            return (open(filepath).read().decode(settings.FILE_CHARSET), filepath) 
    1818        except IOError: 
    1919            tried.append(filepath) 
  • django/branches/unicode/docs/settings.txt

    r5054 r5058  
    426426or ``django.core.mail.mail_managers``. You'll probably want to include the 
    427427trailing space. 
     428 
     429FILE_CHARSET 
     430------------ 
     431 
     432Default: ``'utf-8'`` 
     433 
     434The character encoding used to decode any files read from disk. This includes 
     435template files and initial SQL data files. 
    428436 
    429437FIXTURE_DIRS