summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-01-27 01:47:14 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-01-27 01:47:14 (GMT)
commit255058fae340f354df12bb27533aa66b7f82d30f (patch)
tree6a6c08a244282c55586d77f6a4dbc51e14b675a6
parentd8aef76f6e843368b05d424ad1cc64299288cbb5 (diff)
downloadcpython-255058fae340f354df12bb27533aa66b7f82d30f.zip
cpython-255058fae340f354df12bb27533aa66b7f82d30f.tar.gz
cpython-255058fae340f354df12bb27533aa66b7f82d30f.tar.bz2
don't accept bytes in FileIO.write #7785
-rw-r--r--Lib/test/test_fileio.py5
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/_io/fileio.c2
3 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index 4e6e1b5..d35549f 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -78,6 +78,9 @@ class AutoFileTests(unittest.TestCase):
self.assertEqual(self.f.readline(None), b"hi\n")
self.assertEqual(self.f.readlines(None), [b"bye\n", b"abc"])
+ def test_reject(self):
+ self.assertRaises(TypeError, self.f.write, "Hello!")
+
def testRepr(self):
self.assertEquals(repr(self.f), "<_io.FileIO name=%r mode=%r>"
% (self.f.name, self.f.mode))
@@ -168,7 +171,7 @@ class AutoFileTests(unittest.TestCase):
@ClosedFDRaises
def testErrnoOnClosedWrite(self, f):
- f.write('a')
+ f.write(b'a')
@ClosedFDRaises
def testErrnoOnClosedSeek(self, f):
diff --git a/Misc/NEWS b/Misc/NEWS
index 2e12ffe..c5d0e47 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -234,6 +234,8 @@ C-API
Library
-------
+- Don't accept bytes in FileIO.write().
+
- Removed the functions 'verify' and 'vereq' from Lib/test/support.py.
- Issue #7773: Fix an UnboundLocalError in platform.linux_distribution() when
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 37ddaeb..f02fe8a 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -648,7 +648,7 @@ fileio_write(fileio *self, PyObject *args)
if (!self->writable)
return err_mode("writing");
- if (!PyArg_ParseTuple(args, "s*", &pbuf))
+ if (!PyArg_ParseTuple(args, "y*", &pbuf))
return NULL;
if (_PyVerify_fd(self->fd)) {