mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
Issue #6501: os.device_encoding() returns None on Windows if the application
has no console.
This commit is contained in:
parent
a1ae533ac9
commit
7870bdff5a
2 changed files with 16 additions and 10 deletions
|
@ -153,6 +153,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #6501: os.device_encoding() returns None on Windows if the application
|
||||||
|
has no console.
|
||||||
|
|
||||||
- Issue #12132: Skip test_build_ext in case the xxmodule is not found.
|
- Issue #12132: Skip test_build_ext in case the xxmodule is not found.
|
||||||
|
|
||||||
- Issue #12105: Add O_CLOEXEC to the os module.
|
- Issue #12105: Add O_CLOEXEC to the os module.
|
||||||
|
|
|
@ -8495,6 +8495,9 @@ static PyObject *
|
||||||
device_encoding(PyObject *self, PyObject *args)
|
device_encoding(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
#if defined(MS_WINDOWS) || defined(MS_WIN64)
|
||||||
|
UINT cp;
|
||||||
|
#endif
|
||||||
if (!PyArg_ParseTuple(args, "i:device_encoding", &fd))
|
if (!PyArg_ParseTuple(args, "i:device_encoding", &fd))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!_PyVerify_fd(fd) || !isatty(fd)) {
|
if (!_PyVerify_fd(fd) || !isatty(fd)) {
|
||||||
|
@ -8502,16 +8505,16 @@ device_encoding(PyObject *self, PyObject *args)
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
#if defined(MS_WINDOWS) || defined(MS_WIN64)
|
#if defined(MS_WINDOWS) || defined(MS_WIN64)
|
||||||
if (fd == 0) {
|
if (fd == 0)
|
||||||
char buf[100];
|
cp = GetConsoleCP();
|
||||||
sprintf(buf, "cp%d", GetConsoleCP());
|
else if (fd == 1 || fd == 2)
|
||||||
return PyUnicode_FromString(buf);
|
cp = GetConsoleOutputCP();
|
||||||
}
|
else
|
||||||
if (fd == 1 || fd == 2) {
|
cp = 0;
|
||||||
char buf[100];
|
/* GetConsoleCP() and GetConsoleOutputCP() return 0 if the application
|
||||||
sprintf(buf, "cp%d", GetConsoleOutputCP());
|
has no console */
|
||||||
return PyUnicode_FromString(buf);
|
if (cp != 0)
|
||||||
}
|
return PyUnicode_FromFormat("cp%u", (unsigned int)cp);
|
||||||
#elif defined(CODESET)
|
#elif defined(CODESET)
|
||||||
{
|
{
|
||||||
char *codeset = nl_langinfo(CODESET);
|
char *codeset = nl_langinfo(CODESET);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue