Skip to content

Commit

Permalink
[1.0.X] Fixed #10335: handle system locals unknown to Python in timez…
Browse files Browse the repository at this point in the history
…one name handling. Thanks, mitsuhiko. Backport of [10703] from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10704 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jacobian committed May 8, 2009
1 parent e93b3a7 commit a109a22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 11 additions & 0 deletions django/utils/encoding.py
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,8 @@
import types import types
import urllib import urllib
import locale
import datetime import datetime
import codecs


from django.utils.functional import Promise from django.utils.functional import Promise


Expand Down Expand Up @@ -136,3 +138,12 @@ def iri_to_uri(iri):
return iri return iri
return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?*') return urllib.quote(smart_str(iri), safe='/#%[]=:;$&()+,!?*')



# The encoding of the default system locale but falls back to the
# given fallback encoding if the encoding is unsupported by python or could
# not be determined. See tickets #10335 and #5846
try:
DEFAULT_LOCALE_ENCODING = locale.getdefaultlocale()[1] or 'ascii'
codecs.lookup(DEFAULT_LOCALE_ENCODING)
except:
DEFAULT_LOCALE_ENCODING = 'ascii'
14 changes: 4 additions & 10 deletions django/utils/tzinfo.py
Original file line number Original file line Diff line number Diff line change
@@ -1,15 +1,8 @@
"Implementation of tzinfo classes for use with datetime.datetime." "Implementation of tzinfo classes for use with datetime.datetime."


import locale
import time import time
from datetime import timedelta, tzinfo from datetime import timedelta, tzinfo
from django.utils.encoding import smart_unicode from django.utils.encoding import smart_unicode, smart_str, DEFAULT_LOCALE_ENCODING

try:
DEFAULT_ENCODING = locale.getdefaultlocale()[1] or 'ascii'
except:
# Any problems at all determining the locale and we fallback. See #5846.
DEFAULT_ENCODING = 'ascii'


class FixedOffset(tzinfo): class FixedOffset(tzinfo):
"Fixed offset in minutes east from UTC." "Fixed offset in minutes east from UTC."
Expand Down Expand Up @@ -41,7 +34,7 @@ def __init__(self, dt):
self._tzname = self.tzname(dt) self._tzname = self.tzname(dt)


def __repr__(self): def __repr__(self):
return self._tzname return smart_str(self._tzname)


def utcoffset(self, dt): def utcoffset(self, dt):
if self._isdst(dt): if self._isdst(dt):
Expand All @@ -57,7 +50,8 @@ def dst(self, dt):


def tzname(self, dt): def tzname(self, dt):
try: try:
return smart_unicode(time.tzname[self._isdst(dt)], DEFAULT_ENCODING) return smart_unicode(time.tzname[self._isdst(dt)],
DEFAULT_LOCALE_ENCODING)
except UnicodeDecodeError: except UnicodeDecodeError:
return None return None


Expand Down

0 comments on commit a109a22

Please sign in to comment.