Show More
@@ -60,34 +60,9 b' else:' | |||||
60 | environ = dict((k.encode(u'utf-8'), v.encode(u'utf-8')) |
|
60 | environ = dict((k.encode(u'utf-8'), v.encode(u'utf-8')) | |
61 | for k, v in os.environ.items()) # re-exports |
|
61 | for k, v in os.environ.items()) # re-exports | |
62 |
|
62 | |||
63 | def _getpreferredencoding(): |
|
|||
64 | ''' |
|
|||
65 | On darwin, getpreferredencoding ignores the locale environment and |
|
|||
66 | always returns mac-roman. http://bugs.python.org/issue6202 fixes this |
|
|||
67 | for Python 2.7 and up. This is the same corrected code for earlier |
|
|||
68 | Python versions. |
|
|||
69 |
|
||||
70 | However, we can't use a version check for this method, as some distributions |
|
|||
71 | patch Python to fix this. Instead, we use it as a 'fixer' for the mac-roman |
|
|||
72 | encoding, as it is unlikely that this encoding is the actually expected. |
|
|||
73 | ''' |
|
|||
74 | try: |
|
|||
75 | locale.CODESET |
|
|||
76 | except AttributeError: |
|
|||
77 | # Fall back to parsing environment variables :-( |
|
|||
78 | return locale.getdefaultlocale()[1] |
|
|||
79 |
|
||||
80 | oldloc = locale.setlocale(locale.LC_CTYPE) |
|
|||
81 | locale.setlocale(locale.LC_CTYPE, "") |
|
|||
82 | result = locale.nl_langinfo(locale.CODESET) |
|
|||
83 | locale.setlocale(locale.LC_CTYPE, oldloc) |
|
|||
84 |
|
||||
85 | return result |
|
|||
86 |
|
||||
87 | _encodingfixers = { |
|
63 | _encodingfixers = { | |
88 | '646': lambda: 'ascii', |
|
64 | '646': lambda: 'ascii', | |
89 | 'ANSI_X3.4-1968': lambda: 'ascii', |
|
65 | 'ANSI_X3.4-1968': lambda: 'ascii', | |
90 | 'mac-roman': _getpreferredencoding |
|
|||
91 | } |
|
66 | } | |
92 |
|
67 | |||
93 | try: |
|
68 | try: |
General Comments 0
You need to be logged in to leave comments.
Login now