|
13 | 13 | import idlelib |
14 | 14 | from idlelib.config import idleConf |
15 | 15 |
|
16 | | -if idlelib.testing: # Set True by test.test_idle to avoid setlocale. |
17 | | - encoding = 'utf-8' |
18 | | - errors = 'surrogateescape' |
| 16 | +encoding = 'utf-8' |
| 17 | +if sys.platform == 'win32': |
| 18 | + errors = 'surrogatepass' |
19 | 19 | else: |
20 | | - # Try setting the locale, so that we can find out |
21 | | - # what encoding to use |
22 | | - try: |
23 | | - import locale |
24 | | - locale.setlocale(locale.LC_CTYPE, "") |
25 | | - except (ImportError, locale.Error): |
26 | | - pass |
27 | | - |
28 | | - if sys.platform == 'win32': |
29 | | - encoding = 'utf-8' |
30 | | - errors = 'surrogateescape' |
31 | | - else: |
32 | | - try: |
33 | | - # Different things can fail here: the locale module may not be |
34 | | - # loaded, it may not offer nl_langinfo, or CODESET, or the |
35 | | - # resulting codeset may be unknown to Python. We ignore all |
36 | | - # these problems, falling back to ASCII |
37 | | - locale_encoding = locale.nl_langinfo(locale.CODESET) |
38 | | - if locale_encoding: |
39 | | - codecs.lookup(locale_encoding) |
40 | | - except (NameError, AttributeError, LookupError): |
41 | | - # Try getdefaultlocale: it parses environment variables, |
42 | | - # which may give a clue. Unfortunately, getdefaultlocale has |
43 | | - # bugs that can cause ValueError. |
44 | | - try: |
45 | | - locale_encoding = locale.getdefaultlocale()[1] |
46 | | - if locale_encoding: |
47 | | - codecs.lookup(locale_encoding) |
48 | | - except (ValueError, LookupError): |
49 | | - pass |
| 20 | + errors = 'surrogateescape' |
50 | 21 |
|
51 | | - if locale_encoding: |
52 | | - encoding = locale_encoding.lower() |
53 | | - errors = 'strict' |
54 | | - else: |
55 | | - # POSIX locale or macOS |
56 | | - encoding = 'ascii' |
57 | | - errors = 'surrogateescape' |
58 | | - # Encoding is used in multiple files; locale_encoding nowhere. |
59 | | - # The only use of 'encoding' below is in _decode as initial value |
60 | | - # of deprecated block asking user for encoding. |
61 | | - # Perhaps use elsewhere should be reviewed. |
62 | 22 |
|
63 | 23 | coding_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII) |
64 | 24 | blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)', re.ASCII) |
|
0 commit comments