cpython: ed0c05c739c9 (original) (raw)

Mercurial > cpython

changeset 106428:ed0c05c739c9 3.6

Issue #28164: Correctly handle special console filenames (patch by Eryk Sun) [#28164]

Steve Dower steve.dower@microsoft.com
date Sat, 04 Feb 2017 15:07:46 -0800
parents 0bf72810f8ea
children a5538734cc87 54fea351e3f9
files Lib/test/test_winconsoleio.py Misc/NEWS Modules/_io/winconsoleio.c
diffstat 3 files changed, 76 insertions(+), 21 deletions(-)[+] [-] Lib/test/test_winconsoleio.py 28 Misc/NEWS 2 Modules/_io/winconsoleio.c 67

line wrap: on

line diff

--- a/Lib/test/test_winconsoleio.py +++ b/Lib/test/test_winconsoleio.py @@ -1,9 +1,11 @@ '''Tests for WindowsConsoleIO ''' +import os import io +import sys import unittest -import sys +import tempfile if sys.platform != 'win32': raise unittest.SkipTest("test only relevant on win32") @@ -19,6 +21,16 @@ class WindowsConsoleIOTests(unittest.Tes self.assertFalse(issubclass(ConIO, io.TextIOBase)) def test_open_fd(self):

+

+ try: f = ConIO(0) except ValueError: @@ -56,6 +68,20 @@ class WindowsConsoleIOTests(unittest.Tes f.close() def test_open_name(self):

+

+

+

+ f = ConIO("CON") self.assertTrue(f.readable()) self.assertFalse(f.writable())

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -146,6 +146,8 @@ Library Windows ------- +- Issue #28164: Correctly handle special console filenames (patch by Eryk Sun) +

--- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -60,51 +60,68 @@ char _get_console_type(HANDLE handle) { } char _PyIO_get_console_type(PyObject *path_or_fd) {

-

+ char m = '\0';

if (wcslen(name) != length) { PyMem_Free(name); @@ -370,6 +392,11 @@ static int if (console_type == '\0') console_type = _get_console_type(self->handle);