Opened 9 years ago

Closed 9 years ago

#26103 closed Bug (invalid)

Python 2 crash with non-ASCII characters in settings.LANGUAGES

Reported by: Tim Graham Owned by: nobody
Component: Template system Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As noted on a pull request, adding a non-ASCII character in settings.LANGUAGES, even after adding # -*- coding: utf-8 -*- to django/conf/global_settings.py, causes a test failure on Python 2.7:

======================================================================
ERROR: test_i18n12 (template_tests.syntax_tests.test_i18n.I18nTagTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 331, in run
    testMethod()
  File "/home/tim/code/django/django/test/utils.py", line 208, in inner
    return func(*args, **kwargs)
  File "/home/tim/code/django/tests/template_tests/utils.py", line 61, in inner
    func(self)
  File "/home/tim/code/django/tests/template_tests/syntax_tests/test_i18n.py", line 149, in test_i18n12
    output = self.engine.render_to_string('i18n12')
  File "/home/tim/code/django/django/template/engine.py", line 180, in render_to_string
    return t.render(Context(context))
  File "/home/tim/code/django/django/template/base.py", line 207, in render
    return self._render(context)
  File "/home/tim/code/django/django/test/utils.py", line 94, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/tim/code/django/django/template/base.py", line 976, in render
    bit = node.render_annotated(context)
  File "/home/tim/code/django/django/template/base.py", line 943, in render_annotated
    return self.render(context)
  File "/home/tim/code/django/django/templatetags/i18n.py", line 20, in render
    context[self.variable] = [(k, translation.ugettext(v)) for k, v in settings.LANGUAGES]
  File "/home/tim/code/django/django/utils/translation/__init__.py", line 85, in ugettext
    return _trans.ugettext(message)
  File "/home/tim/code/django/django/utils/translation/trans_real.py", line 321, in ugettext
    return do_translate(message, 'ugettext')
  File "/home/tim/code/django/django/utils/translation/trans_real.py", line 301, in do_translate
    result = getattr(translation_object, translation_function)(eol_message)
  File "/usr/lib/python2.7/gettext.py", line 404, in ugettext
    return unicode(message)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 14: ordinal not in range(128)

Change History (1)

comment:1 by Claude Paroz, 9 years ago

Resolution: invalid
Status: newclosed

Sorry, but adding a non-ASCII non-Unicode string is considered as an error (unless it has a very specific purpose). On Python 2, the u'' prefix is mandatory in such a case.

Note: See TracTickets for help on using tickets.
Back to Top