Ticket #10335: 10335-tzname-locale.patch
File 10335-tzname-locale.patch, 2.1 KB (added by , 16 years ago) |
---|
-
django/utils/tzinfo.py
1 1 "Implementation of tzinfo classes for use with datetime.datetime." 2 2 3 import locale4 3 import time 5 4 from datetime import timedelta, tzinfo 6 from django.utils.encoding import smart_unicode 5 from django.utils.encoding import smart_unicode, smart_str, DEFAULT_LOCALE_ENCODING 7 6 8 try:9 DEFAULT_ENCODING = locale.getdefaultlocale()[1] or 'ascii'10 except:11 # Any problems at all determining the locale and we fallback. See #5846.12 DEFAULT_ENCODING = 'ascii'13 14 7 class FixedOffset(tzinfo): 15 8 "Fixed offset in minutes east from UTC." 16 9 def __init__(self, offset): … … 41 34 self._tzname = self.tzname(dt) 42 35 43 36 def __repr__(self): 44 return s elf._tzname37 return smart_str(self._tzname) 45 38 46 39 def utcoffset(self, dt): 47 40 if self._isdst(dt): … … 57 50 58 51 def tzname(self, dt): 59 52 try: 60 return smart_unicode(time.tzname[self._isdst(dt)], DEFAULT_ENCODING) 53 return smart_unicode(time.tzname[self._isdst(dt)], 54 DEFAULT_LOCALE_ENCODING) 61 55 except UnicodeDecodeError: 62 56 return None 63 57 -
django/utils/encoding.py
1 1 import types 2 2 import urllib 3 import locale 3 4 import datetime 5 import codecs 4 6 5 7 from django.utils.functional import Promise 6 8 … … 136 138 return iri 137 139 return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?*') 138 140 141 142 # The encoding of the default system locale but falls back to the 143 # given fallback encoding if the encoding is unsupported by python or could 144 # not be determined. See tickets #10335 and #5846 145 try: 146 DEFAULT_LOCALE_ENCODING = locale.getdefaultlocale()[1] or 'ascii' 147 codecs.lookup(DEFAULT_LOCALE_ENCODING) 148 except: 149 DEFAULT_LOCALE_ENCODING = 'ascii'