Ticket #4380: 0001-Replace-DEFAULT_CHARSET-with-OUTPUT_CHARSET.patch

File 0001-Replace-DEFAULT_CHARSET-with-OUTPUT_CHARSET.patch, 13.7 KB (added by ctrochalakis, 17 years ago)

replace-DEFAULT_CHARSET

  • django/conf/__init__.py

    From 50f95c753f097fc13e3b6f5f552372d668716a61 Mon Sep 17 00:00:00 2001
    From: Christos Trochalakis <yatiohi@ideopolis.gr>
    Date: Tue, 18 Mar 2008 19:46:30 +0200
    Subject: [PATCH] Replace DEFAULT_CHARSET with OUTPUT_CHARSET
    
    ---
     django/conf/__init__.py                   |    7 +++++++
     django/conf/global_settings.py            |    2 +-
     django/core/mail.py                       |   10 +++++-----
     django/core/serializers/python.py         |    2 +-
     django/core/serializers/xml_serializer.py |    2 +-
     django/http/__init__.py                   |    8 ++++----
     django/test/client.py                     |    2 +-
     django/utils/translation/trans_real.py    |    2 +-
     docs/email.txt                            |    4 ++--
     docs/request_response.txt                 |    4 ++--
     docs/settings.txt                         |    4 ++--
     docs/templates_python.txt                 |    2 +-
     docs/unicode.txt                          |   10 +++++-----
     13 files changed, 33 insertions(+), 26 deletions(-)
    
    diff --git a/django/conf/__init__.py b/django/conf/__init__.py
    index 61d9ff7..8deb736 100644
    a b class Settings(object):  
    9090        # as strings.
    9191        tuple_settings = ("INSTALLED_APPS", "TEMPLATE_DIRS")
    9292
     93        # If DEFAULT_CHARSET is specified, populate OUTPUT_CHARSET from it.
     94        try:
     95            setattr(self, "OUTPUT_CHARSET", getattr(mod, "DEFAULT_CHARSET"))
     96        except AttributeError, e:
     97            pass
     98
    9399        for setting in dir(mod):
    94100            if setting == setting.upper():
    95101                setting_value = getattr(mod, setting)
    class Settings(object):  
    97103                    setting_value = (setting_value,) # In case the user forgot the comma.
    98104                setattr(self, setting, setting_value)
    99105
     106
    100107        # Expand entries in INSTALLED_APPS like "django.contrib.*" to a list
    101108        # of all those apps.
    102109        new_installed_apps = []
  • django/conf/global_settings.py

    diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
    index 6be789a..287b8b9 100644
    a b MANAGERS = ADMINS  
    102102# MIME type isn't manually specified. These are used to construct the
    103103# Content-Type header.
    104104DEFAULT_CONTENT_TYPE = 'text/html'
    105 DEFAULT_CHARSET = 'utf-8'
     105OUTPUT_CHARSET = 'utf-8'
    106106
    107107# Encoding of files read from disk (template and initial SQL files).
    108108FILE_CHARSET = 'utf-8'
  • django/core/mail.py

    diff --git a/django/core/mail.py b/django/core/mail.py
    index 72343cb..5ba545e 100644
    a b def forbid_multi_line_headers(name, val):  
    7878            result = []
    7979            for item in val.split(', '):
    8080                nm, addr = parseaddr(item)
    81                 nm = str(Header(nm, settings.DEFAULT_CHARSET))
     81                nm = str(Header(nm, settings.OUTPUT_CHARSET))
    8282                result.append(formataddr((nm, str(addr))))
    8383            val = ', '.join(result)
    8484        else:
    85             val = Header(force_unicode(val), settings.DEFAULT_CHARSET)
     85            val = Header(force_unicode(val), settings.OUTPUT_CHARSET)
    8686    return name, val
    8787
    8888class SafeMIMEText(MIMEText):
    class EmailMessage(object):  
    220220        return self.connection
    221221
    222222    def message(self):
    223         encoding = self.encoding or settings.DEFAULT_CHARSET
    224         msg = SafeMIMEText(smart_str(self.body, settings.DEFAULT_CHARSET), self.content_subtype, encoding)
     223        encoding = self.encoding or settings.OUTPUT_CHARSET
     224        msg = SafeMIMEText(smart_str(self.body, settings.OUTPUT_CHARSET), self.content_subtype, encoding)
    225225        if self.attachments:
    226226            body_msg = msg
    227227            msg = SafeMIMEMultipart(_subtype=self.multipart_subtype)
    class EmailMessage(object):  
    288288        basetype, subtype = mimetype.split('/', 1)
    289289        if basetype == 'text':
    290290            attachment = SafeMIMEText(smart_str(content,
    291                 settings.DEFAULT_CHARSET), subtype, settings.DEFAULT_CHARSET)
     291                settings.OUTPUT_CHARSET), subtype, settings.OUTPUT_CHARSET)
    292292        else:
    293293            # Encode non-text attachments with base64.
    294294            attachment = MIMEBase(basetype, subtype)
  • django/core/serializers/python.py

    diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py
    index cedab06..02e5636 100644
    a b def Deserializer(object_list, **options):  
    7272        # Handle each field
    7373        for (field_name, field_value) in d["fields"].iteritems():
    7474            if isinstance(field_value, str):
    75                 field_value = smart_unicode(field_value, options.get("encoding", settings.DEFAULT_CHARSET), strings_only=True)
     75                field_value = smart_unicode(field_value, options.get("encoding", settings.OUTPUT_CHARSET), strings_only=True)
    7676
    7777            field = Model._meta.get_field(field_name)
    7878
  • django/core/serializers/xml_serializer.py

    diff --git a/django/core/serializers/xml_serializer.py b/django/core/serializers/xml_serializer.py
    index 667faf7..fa0c794 100644
    a b class Serializer(base.Serializer):  
    2222        """
    2323        Start serialization -- open the XML document and the root element.
    2424        """
    25         self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.DEFAULT_CHARSET))
     25        self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.OUTPUT_CHARSET))
    2626        self.xml.startDocument()
    2727        self.xml.startElement("django-objects", {"version" : "1.0"})
    2828
  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index 5439aa6..307dc83 100644
    a b class QueryDict(MultiValueDict):  
    139139    This is immutable unless you create a copy of it.
    140140
    141141    Values retrieved from this class are converted from the given encoding
    142     (DEFAULT_CHARSET by default) to unicode.
     142    (OUTPUT_CHARSET by default) to unicode.
    143143    """
    144144    def __init__(self, query_string, mutable=False, encoding=None):
    145145        MultiValueDict.__init__(self)
    class QueryDict(MultiValueDict):  
    147147            # *Important*: do not import settings any earlier because of note
    148148            # in core.handlers.modpython.
    149149            from django.conf import settings
    150             encoding = settings.DEFAULT_CHARSET
     150            encoding = settings.OUTPUT_CHARSET
    151151        self.encoding = encoding
    152152        self._mutable = True
    153153        for key, value in parse_qsl((query_string or ''), True): # keep_blank_values=True
    class HttpResponse(object):  
    259259    def __init__(self, content='', mimetype=None, status=None,
    260260            content_type=None):
    261261        from django.conf import settings
    262         self._charset = settings.DEFAULT_CHARSET
     262        self._charset = settings.OUTPUT_CHARSET
    263263        if mimetype:
    264264            content_type = mimetype     # For backwards compatibility
    265265        if not content_type:
    266266            content_type = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE,
    267                     settings.DEFAULT_CHARSET)
     267                    settings.OUTPUT_CHARSET)
    268268        if not isinstance(content, basestring) and hasattr(content, '__iter__'):
    269269            self._container = content
    270270            self._is_string = False
  • django/test/client.py

    diff --git a/django/test/client.py b/django/test/client.py
    index 67d3aa9..af2699f 100644
    a b def encode_multipart(boundary, data):  
    6161    as an application/octet-stream; otherwise, str(value) will be sent.
    6262    """
    6363    lines = []
    64     to_str = lambda s: smart_str(s, settings.DEFAULT_CHARSET)
     64    to_str = lambda s: smart_str(s, settings.OUTPUT_CHARSET)
    6565    for (key, value) in data.items():
    6666        if isinstance(value, file):
    6767            lines.extend([
  • django/utils/translation/trans_real.py

    diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
    index bcc5e4b..537a44c 100644
    a b def to_language(locale):  
    6565class DjangoTranslation(gettext_module.GNUTranslations):
    6666    """
    6767    This class sets up the GNUTranslations context with regard to output
    68     charset. Django uses a defined DEFAULT_CHARSET as the output charset on
     68    charset. Django uses a defined OUTPUT_CHARSET as the output charset on
    6969    Python 2.4. With Python 2.3, use DjangoTranslation23.
    7070    """
    7171    def __init__(self, *args, **kw):
  • docs/email.txt

    diff --git a/docs/email.txt b/docs/email.txt
    index 7f2eef6..7ea9843 100644
    a b settings, if set, are used to authenticate to the SMTP server, and the  
    2828.. note::
    2929
    3030    The character set of e-mail sent with ``django.core.mail`` will be set to
    31     the value of your `DEFAULT_CHARSET`_ setting.
     31    the value of your `OUTPUT_CHARSET`_ setting.
    3232
    33 .. _DEFAULT_CHARSET: ../settings/#default-charset
     33.. _OUTPUT_CHARSET: ../settings/#output-charset
    3434.. _EMAIL_HOST: ../settings/#email-host
    3535.. _EMAIL_PORT: ../settings/#email-port
    3636.. _EMAIL_HOST_USER: ../settings/#email-host-user
  • docs/request_response.txt

    diff --git a/docs/request_response.txt b/docs/request_response.txt
    index e50cfc5..f71905f 100644
    a b All attributes except ``session`` should be considered read-only.  
    4242    **New in Django development version**
    4343
    4444    A string representing the current encoding used to decode form submission
    45     data (or ``None``, which means the ``DEFAULT_CHARSET`` setting is used).
     45    data (or ``None``, which means the ``OUTPUT_CHARSET`` setting is used).
    4646    You can write to this attribute to change the encoding used when accessing
    4747    the form data. Any subsequent attribute accesses (such as reading from
    4848    ``GET`` or ``POST``) will use the new ``encoding`` value.  Useful if you
    49     know the form data is not in the ``DEFAULT_CHARSET`` encoding.
     49    know the form data is not in the ``OUTPUT_CHARSET`` encoding.
    5050
    5151``GET``
    5252    A dictionary-like object containing all given HTTP GET parameters. See the
  • docs/settings.txt

    diff --git a/docs/settings.txt b/docs/settings.txt
    index 77e3c66..2a13333 100644
    a b are inappropriate for public consumption. File paths, configuration options, and  
    388388the like all give attackers extra information about your server. Never deploy a
    389389site with ``DEBUG`` turned on.
    390390
    391 DEFAULT_CHARSET
     391OUTPUT_CHARSET
    392392---------------
    393393
    394394Default: ``'utf-8'``
    DEFAULT_CONTENT_TYPE  
    403403Default: ``'text/html'``
    404404
    405405Default content type to use for all ``HttpResponse`` objects, if a MIME type
    406 isn't manually specified. Used with ``DEFAULT_CHARSET`` to construct the
     406isn't manually specified. Used with ``OUTPUT_CHARSET`` to construct the
    407407``Content-Type`` header.
    408408
    409409DEFAULT_FROM_EMAIL
  • docs/templates_python.txt

    diff --git a/docs/templates_python.txt b/docs/templates_python.txt
    index 43ef016..e940c81 100644
    a b pieces of the templating system and then, *before* you call any of the  
    14531453templating functions, call ``django.conf.settings.configure()`` with any
    14541454settings you wish to specify. You might want to consider setting at least
    14551455``TEMPLATE_DIRS`` (if you're going to use template loaders),
    1456 ``DEFAULT_CHARSET`` (although the default of ``utf-8`` is probably fine) and
     1456``OUTPUT_CHARSET`` (although the default of ``utf-8`` is probably fine) and
    14571457``TEMPLATE_DEBUG``. All available settings are described in the
    14581458`settings documentation`_, and any setting starting with *TEMPLATE_*
    14591459is of obvious interest.
  • docs/unicode.txt

    diff --git a/docs/unicode.txt b/docs/unicode.txt
    index a2c4e7f..cbbef2b 100644
    a b You can use Unicode strings, or you can use normal strings (sometimes called  
    6060If your code only uses ASCII data, it's safe to use your normal strings,
    6161passing them around at will, because ASCII is a subset of UTF-8.
    6262
    63 Don't be fooled into thinking that if your ``DEFAULT_CHARSET`` setting is set
     63Don't be fooled into thinking that if your ``OUTPUT_CHARSET`` setting is set
    6464to something other than ``'utf-8'`` you can use that other encoding in your
    65 bytestrings! ``DEFAULT_CHARSET`` only applies to the strings generated as
     65bytestrings! ``OUTPUT_CHARSET`` only applies to the strings generated as
    6666the result of template rendering (and e-mail). Django will always assume UTF-8
    6767encoding for internal bytestrings. The reason for this is that the
    68 ``DEFAULT_CHARSET`` setting is not actually under your control (if you are the
     68``OUTPUT_CHARSET`` setting is not actually under your control (if you are the
    6969application developer). It's under the control of the person installing and
    7070using your application -- and if that person chooses a different setting, your
    7171code must still continue to work. Ergo, it cannot rely on that setting.
    setting to the encoding of the files on disk. When Django reads in a template  
    293293file, it will convert the data from this encoding to Unicode. (``FILE_CHARSET``
    294294is set to ``'utf-8'`` by default.)
    295295
    296 The ``DEFAULT_CHARSET`` setting controls the encoding of rendered templates.
     296The ``OUTPUT_CHARSET`` setting controls the encoding of rendered templates.
    297297This is set to UTF-8 by default.
    298298
    299299Template tags and filters
    two fields will return their members as Unicode data. All other attributes and  
    345345methods of ``HttpRequest`` return data exactly as it was submitted by the
    346346client.
    347347
    348 By default, the ``DEFAULT_CHARSET`` setting is used as the assumed encoding
     348By default, the ``OUTPUT_CHARSET`` setting is used as the assumed encoding
    349349for form data. If you need to change this for a particular form, you can set
    350350the ``encoding`` attribute on an ``HttpRequest`` instance. For example::
    351351
Back to Top