From: Victor Stinner Date: Mon, 3 Dec 2012 11:48:53 +0000 (+0100) Subject: (Merge 3.2) Issue #16416: On Mac OS X, operating system data are now always X-Git-Tag: v3.3.1rc1~568 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2660e427d1abcae9fc60115c45619ed2286fc560;p=python (Merge 3.2) Issue #16416: On Mac OS X, operating system data are now always encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding (which may be ASCII if no locale environment variable is set), to avoid inconsistencies with os.fsencode() and os.fsdecode() functions which are already using UTF-8/surrogateescape. --- 2660e427d1abcae9fc60115c45619ed2286fc560 diff --cc Misc/NEWS index 6eff12c84e,fbcfe90c0b..c695be511c --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -12,12 -10,13 +12,18 @@@ What's New in Python 3.3.1 Core and Builtins ----------------- + - Issue #16416: On Mac OS X, operating system data are now always + encoded/decoded to/from UTF-8/surrogateescape, instead of the locale encoding + (which may be ASCII if no locale environment variable is set), to avoid + inconsistencies with os.fsencode() and os.fsdecode() functions which are + already using UTF-8/surrogateescape. + -- Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h +- Issue #16588: Silence unused-but-set warnings in Python/thread_pthread + +- Issue #16546: Fix: ast.YieldFrom argument is now mandatory. + +- Issue #16514: Fix regression causing a traceback when sys.path[0] is None + (actually, any non-string or non-bytes type). - Issue #16306: Fix multiple error messages when unknown command line parameters where passed to the interpreter. Patch by Hieu Nguyen. diff --cc Modules/python.c index c70bf37827,2be69f1f54..2c08b96856 --- a/Modules/python.c +++ b/Modules/python.c @@@ -45,13 -41,8 +41,9 @@@ main(int argc, char **argv oldloc = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { - #ifdef __APPLE__ - argv_copy[i] = _Py_DecodeUTF8_surrogateescape(argv[i], strlen(argv[i])); - #else argv_copy[i] = _Py_char2wchar(argv[i], NULL); - #endif if (!argv_copy[i]) { + free(oldloc); fprintf(stderr, "Fatal Python error: " "unable to decode the command line argument #%i\n", i + 1); diff --cc Python/fileutils.c index 976c04b117,cba6696695..2e9ea359da --- a/Python/fileutils.c +++ b/Python/fileutils.c @@@ -4,40 -3,10 +4,44 @@@ # include #endif +#ifdef HAVE_LANGINFO_H +#include +#endif + + #ifdef __APPLE__ + extern wchar_t* _Py_DecodeUTF8_surrogateescape(const char *s, Py_ssize_t size); + #endif + +PyObject * +_Py_device_encoding(int fd) +{ +#if defined(MS_WINDOWS) || defined(MS_WIN64) + UINT cp; +#endif + if (!_PyVerify_fd(fd) || !isatty(fd)) { + Py_RETURN_NONE; + } +#if defined(MS_WINDOWS) || defined(MS_WIN64) + if (fd == 0) + cp = GetConsoleCP(); + else if (fd == 1 || fd == 2) + cp = GetConsoleOutputCP(); + else + cp = 0; + /* GetConsoleCP() and GetConsoleOutputCP() return 0 if the application + has no console */ + if (cp != 0) + return PyUnicode_FromFormat("cp%u", (unsigned int)cp); +#elif defined(CODESET) + { + char *codeset = nl_langinfo(CODESET); + if (codeset != NULL && codeset[0] != 0) + return PyUnicode_FromString(codeset); + } +#endif + Py_RETURN_NONE; +} + #ifdef HAVE_STAT /* Decode a byte string from the locale encoding with the @@@ -165,9 -141,9 +180,10 @@@ _Py_char2wchar(const char* arg, size_t *size = out - res; return res; oom: - fprintf(stderr, "out of memory\n"); + if (size != NULL) + *size = (size_t)-1; return NULL; + #endif /* __APPLE__ */ } /* Encode a (wide) character string to the locale encoding with the