| 1 | From 2ac494f71676e8cf824ae7eced1bca0848bb5a59 Mon Sep 17 00:00:00 2001 |
| 2 | From: Thomas A Caswell <tcaswell@gmail.com> |
| 3 | Date: Mon, 15 Feb 2016 15:35:59 -0500 |
| 4 | Subject: [PATCH] Merge pull request #5931 from ntessore/patch-1 |
| 5 | |
| 6 | use `locale.getpreferredencoding()` to prevent OS X locale issues |
| 7 | --- |
| 8 | lib/matplotlib/__init__.py | 5 +++-- |
| 9 | 1 file changed, 3 insertions(+), 2 deletions(-) |
| 10 | |
| 11 | diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py |
| 12 | index f7f4d53..53216ab 100644 |
| 13 | --- lib/matplotlib/__init__.py |
| 14 | +++ lib/matplotlib/__init__.py |
| 15 | @@ -997,7 +997,7 @@ def _open_file_or_url(fname): |
| 16 | f.close() |
| 17 | else: |
| 18 | fname = os.path.expanduser(fname) |
| 19 | - encoding = locale.getdefaultlocale()[1] |
| 20 | + encoding = locale.getpreferredencoding(do_setlocale=False) |
| 21 | if encoding is None: |
| 22 | encoding = "utf-8" |
| 23 | with io.open(fname, encoding=encoding) as f: |
| 24 | @@ -1038,7 +1038,8 @@ def _rc_params_in_file(fname, fail_on_error=False): |
| 25 | warnings.warn( |
| 26 | ('Cannot decode configuration file %s with ' |
| 27 | 'encoding %s, check LANG and LC_* variables') |
| 28 | - % (fname, locale.getdefaultlocale()[1] or 'utf-8 (default)')) |
| 29 | + % (fname, locale.getpreferredencoding(do_setlocale=False) or |
| 30 | + 'utf-8 (default)')) |
| 31 | raise |
| 32 | |
| 33 | config = RcParams() |