Ticket #10335: tzinfo-getdefaultencoding-only-if-unchanged-fails.patch

File tzinfo-getdefaultencoding-only-if-unchanged-fails.patch, 679 bytes (added by Gunnlaugur Þór Briem, 15 years ago)

Another patch, more conservative. This one changes nothing unless the getdefaultlocale()[1] encoding is unknown to Python.

  • django/utils/tzinfo.py

     
    44import time
    55from datetime import timedelta, tzinfo
    66from django.utils.encoding import smart_unicode
     7import sys
     8from encodings import codecs
    79
    810try:
    911    DEFAULT_ENCODING = locale.getdefaultlocale()[1] or 'ascii'
     12    try:
     13        codecs.getdecoder(DEFAULT_ENCODING)
     14    except LookupError:
     15        DEFAULT_ENCODING = sys.getdefaultencoding() or 'ascii'
    1016except:
    1117    # Any problems at all determining the locale and we fallback. See #5846.
    1218    DEFAULT_ENCODING = 'ascii'
Back to Top