diff options
author | Brett Cannon <brett@python.org> | 2012-02-29 18:31:31 -0500 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-02-29 18:31:31 -0500 |
commit | efb00c0cc189c1fdee329e8b7fdd07b3fd4a54cf (patch) | |
tree | 22dc683979e0dd42d049416797b756a5c6a053cd /Modules/posixmodule.c | |
parent | 54c32032aa28bdfead50714bf7861c98a9843597 (diff) | |
download | cpython-git-efb00c0cc189c1fdee329e8b7fdd07b3fd4a54cf.tar.gz |
Issue #14153 Create _Py_device_encoding() to prevent _io from having to import
the os module.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index dbace1a891..628b0b9463 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -9326,35 +9326,11 @@ static PyObject * device_encoding(PyObject *self, PyObject *args) { int fd; -#if defined(MS_WINDOWS) || defined(MS_WIN64) - UINT cp; -#endif + if (!PyArg_ParseTuple(args, "i:device_encoding", &fd)) return NULL; - if (!_PyVerify_fd(fd) || !isatty(fd)) { - Py_INCREF(Py_None); - return Py_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_INCREF(Py_None); - return Py_None; + + return _Py_device_encoding(fd); } #ifdef __VMS |