Show More
@@ -15,6 +15,7 b' Utilities for dealing with text encodings' | |||||
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | import sys |
|
16 | import sys | |
17 | import locale |
|
17 | import locale | |
|
18 | import warnings | |||
18 |
|
19 | |||
19 | # to deal with the possibility of sys.std* not being a stream at all |
|
20 | # to deal with the possibility of sys.std* not being a stream at all | |
20 | def get_stream_enc(stream, default=None): |
|
21 | def get_stream_enc(stream, default=None): | |
@@ -51,6 +52,16 b' def getdefaultencoding():' | |||||
51 | enc = locale.getpreferredencoding() |
|
52 | enc = locale.getpreferredencoding() | |
52 | except Exception: |
|
53 | except Exception: | |
53 | pass |
|
54 | pass | |
54 |
|
|
55 | enc = enc or sys.getdefaultencoding() | |
|
56 | # On windows `cp0` can be returned to indicate that there is no code page. | |||
|
57 | # Since cp0 is an invalid encoding return instead cp1252 which is the | |||
|
58 | # Western European default. | |||
|
59 | if enc == 'cp0': | |||
|
60 | warnings.warn( | |||
|
61 | "Invalid code page cp0 detected - using cp1252 instead." | |||
|
62 | "If cp1252 is incorrect please ensure a valid code page " | |||
|
63 | "is defined for the process.", RuntimeWarning) | |||
|
64 | return 'cp1252' | |||
|
65 | return enc | |||
55 |
|
66 | |||
56 | DEFAULT_ENCODING = getdefaultencoding() |
|
67 | DEFAULT_ENCODING = getdefaultencoding() |
General Comments 0
You need to be logged in to leave comments.
Login now