Permalink
Browse files

bz19249: Catch errors that can be thrown from locale.getlocale().

... to prevent a crash on startup on malformed/invalid locale
settings by user.
  • Loading branch information...
1 parent 8e858ab commit 4551f243e3a44713744eb1a0389f522fbb0c28ce Geoffrey Lee committed Jun 26, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 tv/lib/gtcache.py
View
8 tv/lib/gtcache.py
@@ -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:
@@ -113,8 +119,6 @@ def init(languages=None, localedir=None):
codeset="UTF-8",
fallback=True)
- codeset = locale.getlocale()[1]
-
_gtcache = {}
def declarify(text):

0 comments on commit 4551f24

Please sign in to comment.