Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: fix_encoding.py

Issue 6696094: Catch exception thrown on certain locale setup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Trap more exceptions... Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Collection of functions and classes to fix various encoding problems on 5 """Collection of functions and classes to fix various encoding problems on
6 multiple platforms with python. 6 multiple platforms with python.
7 """ 7 """
8 8
9 import codecs 9 import codecs
10 import locale 10 import locale
(...skipping 28 matching lines...) Expand all
39 39
40 # Regenerate setdefaultencoding. 40 # Regenerate setdefaultencoding.
41 reload(sys) 41 reload(sys)
42 # Module 'sys' has no 'setdefaultencoding' member 42 # Module 'sys' has no 'setdefaultencoding' member
43 # pylint: disable=E1101 43 # pylint: disable=E1101
44 sys.setdefaultencoding('utf-8') 44 sys.setdefaultencoding('utf-8')
45 for attr in dir(locale): 45 for attr in dir(locale):
46 if attr[0:3] != 'LC_': 46 if attr[0:3] != 'LC_':
47 continue 47 continue
48 aref = getattr(locale, attr) 48 aref = getattr(locale, attr)
49 locale.setlocale(aref, '') 49 try:
50 locale.setlocale(aref, '')
51 except locale.Error:
52 continue
50 try: 53 try:
51 lang = locale.getlocale(aref)[0] 54 lang = locale.getlocale(aref)[0]
52 except (TypeError, ValueError): 55 except (TypeError, ValueError):
53 lang = None 56 continue
54 if lang: 57 if lang:
55 try: 58 try:
56 locale.setlocale(aref, (lang, 'UTF-8')) 59 locale.setlocale(aref, (lang, 'UTF-8'))
57 except locale.Error: 60 except locale.Error:
58 os.environ[attr] = lang + '.UTF-8' 61 os.environ[attr] = lang + '.UTF-8'
59 locale.setlocale(locale.LC_ALL, '') 62 try:
63 locale.setlocale(locale.LC_ALL, '')
64 except locale.Error:
65 pass
60 return True 66 return True
61 67
62 68
63 ############################### 69 ###############################
64 # Windows specific 70 # Windows specific
65 71
66 72
67 def fix_win_sys_argv(encoding): 73 def fix_win_sys_argv(encoding):
68 """Converts sys.argv to 'encoding' encoded string. 74 """Converts sys.argv to 'encoding' encoded string.
69 75
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 if sys.platform == 'win32': 353 if sys.platform == 'win32':
348 ret &= fix_win_codec() 354 ret &= fix_win_codec()
349 355
350 ret &= fix_default_encoding() 356 ret &= fix_default_encoding()
351 357
352 if sys.platform == 'win32': 358 if sys.platform == 'win32':
353 encoding = sys.getdefaultencoding() 359 encoding = sys.getdefaultencoding()
354 ret &= fix_win_sys_argv(encoding) 360 ret &= fix_win_sys_argv(encoding)
355 ret &= fix_win_console(encoding) 361 ret &= fix_win_console(encoding)
356 return ret 362 return ret
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698