Skip to content

Commit

Permalink
bz19249: Catch errors that can be thrown from locale.getlocale().
Browse files Browse the repository at this point in the history
... to prevent a crash on startup on malformed/invalid locale
settings by user.
  • Loading branch information
Geoffrey Lee committed Jun 26, 2012
1 parent 8e858ab commit 4551f24
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tv/lib/gtcache.py
Expand Up @@ -101,6 +101,12 @@ def init(languages=None, localedir=None):
except locale.Error:
print "gtcache.init: setlocale failed. setting locale to 'C'"
locale.setlocale(locale.LC_ALL, 'C')
try:
codeset = locale.getlocale()[1]
except (TypeError, ValueError):
print "gtcache.init: getlocale failed. Reinit with 'C'"
locale.setlocale(locale.LC_ALL, 'C')
codeset = locale.getlocale()[1]

# bz:17713 - convert to str in utf-8 encoding before trying to use.
if languages:
Expand All @@ -113,8 +119,6 @@ def init(languages=None, localedir=None):
codeset="UTF-8",
fallback=True)

codeset = locale.getlocale()[1]

_gtcache = {}

def declarify(text):
Expand Down

0 comments on commit 4551f24

Please sign in to comment.