[Python-checkins] bpo-31966: Fixed WindowsConsoleIO.write() for writing empty data. (GH-5754)
Miss Islington (bot)
webhook-mailer at python.org
Sat Feb 24 12:39:21 EST 2018
https://github.com/python/cpython/commit/e49bf0f353a968cddc4d8e6ea668b9d2d116e2ac
commit: e49bf0f353a968cddc4d8e6ea668b9d2d116e2ac
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-02-24T09:39:18-08:00
summary:
bpo-31966: Fixed WindowsConsoleIO.write() for writing empty data. (GH-5754)
(cherry picked from commit 42c35d9c0c8175332f50fbe034a001fe52f057b9)
Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>
files:
A Misc/NEWS.d/next/Windows/2018-02-19-13-54-42.bpo-31966._Q3HPb.rst
M Lib/test/test_winconsoleio.py
M Modules/_io/winconsoleio.c
diff --git a/Lib/test/test_winconsoleio.py b/Lib/test/test_winconsoleio.py
index 656483cf1621..a78fa4d7d919 100644
--- a/Lib/test/test_winconsoleio.py
+++ b/Lib/test/test_winconsoleio.py
@@ -121,6 +121,10 @@ def test_conout_path(self):
else:
self.assertNotIsInstance(f, ConIO)
+ def test_write_empty_data(self):
+ with ConIO('CONOUT$', 'w') as f:
+ self.assertEqual(f.write(b''), 0)
+
def assertStdinRoundTrip(self, text):
stdin = open('CONIN$', 'r')
old_stdin = sys.stdin
diff --git a/Misc/NEWS.d/next/Windows/2018-02-19-13-54-42.bpo-31966._Q3HPb.rst b/Misc/NEWS.d/next/Windows/2018-02-19-13-54-42.bpo-31966._Q3HPb.rst
new file mode 100644
index 000000000000..042a4d835abf
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2018-02-19-13-54-42.bpo-31966._Q3HPb.rst
@@ -0,0 +1 @@
+Fixed WindowsConsoleIO.write() for writing empty data.
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
index 30d1c767afcf..b85c11b3405a 100644
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -964,6 +964,9 @@ _io__WindowsConsoleIO_write_impl(winconsoleio *self, Py_buffer *b)
if (!self->writable)
return err_mode("writing");
+ if (!b->len) {
+ return PyLong_FromLong(0);
+ }
if (b->len > BUFMAX)
len = BUFMAX;
else
More information about the Python-checkins
mailing list