summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authordoko <doko@ubuntu.com>2014-04-17 19:49:00 +0200
committerdoko <doko@ubuntu.com>2014-04-17 19:49:00 +0200
commitbcae4a42668b308d4781d023333558dfc2f75abe (patch)
tree6d1a988083ec2e765402a1cb8a7d7dc36860bb48 /Python/pythonrun.c
parent63e2c6a951602f90e6757e36902459b5adcfcda1 (diff)
parent321b63247465f93573e34c50bc3d2e9c6e7d89b0 (diff)
downloadcpython-bcae4a42668b308d4781d023333558dfc2f75abe.tar.gz
- Merge 3.4
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index b3991ead91..4fd51499c7 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -15,6 +15,7 @@
#include "ast.h"
#include "marshal.h"
#include "osdefs.h"
+#include <locale.h>
#ifdef HAVE_SIGNAL_H
#include <signal.h>
@@ -25,7 +26,6 @@
#endif
#ifdef HAVE_LANGINFO_H
-#include <locale.h>
#include <langinfo.h>
#endif
@@ -1160,6 +1160,15 @@ initstdio(void)
encoding = _Py_StandardStreamEncoding;
errors = _Py_StandardStreamErrors;
if (!encoding || !errors) {
+ if (!errors) {
+ /* When the LC_CTYPE locale is the POSIX locale ("C locale"),
+ stdin and stdout use the surrogateescape error handler by
+ default, instead of the strict error handler. */
+ char *loc = setlocale(LC_CTYPE, NULL);
+ if (loc != NULL && strcmp(loc, "C") == 0)
+ errors = "surrogateescape";
+ }
+
pythonioencoding = Py_GETENV("PYTHONIOENCODING");
if (pythonioencoding) {
char *err;
@@ -1172,7 +1181,7 @@ initstdio(void)
if (err) {
*err = '\0';
err++;
- if (*err && !errors) {
+ if (*err && !_Py_StandardStreamErrors) {
errors = err;
}
}