| OLD | NEW |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 try: | 49 try: |
| 50 locale.setlocale(aref, '') | 50 locale.setlocale(aref, '') |
| 51 except locale.Error: | 51 except locale.Error: |
| 52 continue | 52 continue |
| 53 try: | 53 try: |
| 54 lang = locale.getlocale(aref)[0] | 54 lang, _ = locale.getdefaultlocale() |
| 55 except (TypeError, ValueError): | 55 except (TypeError, ValueError): |
| 56 continue | 56 continue |
| 57 if lang: | 57 if lang: |
| 58 try: | 58 try: |
| 59 locale.setlocale(aref, (lang, 'UTF-8')) | 59 locale.setlocale(aref, (lang, 'UTF-8')) |
| 60 except locale.Error: | 60 except locale.Error: |
| 61 os.environ[attr] = lang + '.UTF-8' | 61 os.environ[attr] = lang + '.UTF-8' |
| 62 try: | 62 try: |
| 63 locale.setlocale(locale.LC_ALL, '') | 63 locale.setlocale(locale.LC_ALL, '') |
| 64 except locale.Error: | 64 except locale.Error: |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 if sys.platform == 'win32': | 362 if sys.platform == 'win32': |
| 363 ret &= fix_win_codec() | 363 ret &= fix_win_codec() |
| 364 | 364 |
| 365 ret &= fix_default_encoding() | 365 ret &= fix_default_encoding() |
| 366 | 366 |
| 367 if sys.platform == 'win32': | 367 if sys.platform == 'win32': |
| 368 encoding = sys.getdefaultencoding() | 368 encoding = sys.getdefaultencoding() |
| 369 ret &= fix_win_sys_argv(encoding) | 369 ret &= fix_win_sys_argv(encoding) |
| 370 ret &= fix_win_console(encoding) | 370 ret &= fix_win_console(encoding) |
| 371 return ret | 371 return ret |
| OLD | NEW |