From cfa826c9845122d445dce4f51f556381865dbed3 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Fri, 25 Mar 2011 00:47:57 +0000 Subject: [PATCH] Catch exception thrown on certain locale setup Mostly happening on Mac. Will investigate later. TBR=dpranke BUG= TEST= Review URL: http://codereview.chromium.org/6696094 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@79354 0039d316-1c4b-4281-b951-d872f2087c98 --- fix_encoding.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fix_encoding.py b/fix_encoding.py index 5bfb58e30..ab418695b 100644 --- a/fix_encoding.py +++ b/fix_encoding.py @@ -46,17 +46,23 @@ def fix_default_encoding(): if attr[0:3] != 'LC_': continue aref = getattr(locale, attr) - locale.setlocale(aref, '') + try: + locale.setlocale(aref, '') + except locale.Error: + continue try: lang = locale.getlocale(aref)[0] except (TypeError, ValueError): - lang = None + continue if lang: try: locale.setlocale(aref, (lang, 'UTF-8')) except locale.Error: os.environ[attr] = lang + '.UTF-8' - locale.setlocale(locale.LC_ALL, '') + try: + locale.setlocale(locale.LC_ALL, '') + except locale.Error: + pass return True