diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-11-22 01:59:15 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-11-22 01:59:15 (GMT) |
commit | bfc51567f5ca1af7e1950519b8b34037a4f11bb0 (patch) | |
tree | 63e28192327207e4a1d69867661da41e2be8dbd7 | |
parent | c078f929cb20f3e48fc1636ae8c211bc4f91a483 (diff) | |
download | cpython-bfc51567f5ca1af7e1950519b8b34037a4f11bb0.zip cpython-bfc51567f5ca1af7e1950519b8b34037a4f11bb0.tar.gz cpython-bfc51567f5ca1af7e1950519b8b34037a4f11bb0.tar.bz2 |
backport r67325: make FileIO.mode always contain 'b'
-rw-r--r-- | Lib/test/test_fileio.py | 4 | ||||
-rw-r--r-- | Lib/test/test_io.py | 14 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Modules/_fileio.c | 8 |
4 files changed, 16 insertions, 12 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index cbc7165..c978779 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -50,7 +50,7 @@ class AutoFileTests(unittest.TestCase): # verify expected attributes exist f = self.f - self.assertEquals(f.mode, "w") + self.assertEquals(f.mode, "wb") self.assertEquals(f.closed, False) # verify the attributes are readonly @@ -160,7 +160,7 @@ class OtherFileTests(unittest.TestCase): def testModeStrings(self): # check invalid mode strings - for mode in ("", "aU", "wU+", "rb", "rt"): + for mode in ("", "aU", "wU+", "rw", "rt"): try: f = _fileio._FileIO(TESTFN, mode) except ValueError: diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index c9bd38d..eb41d1f 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1266,7 +1266,7 @@ class MiscIOTest(unittest.TestCase): def test_attributes(self): f = io.open(test_support.TESTFN, "wb", buffering=0) - self.assertEquals(f.mode, "w") + self.assertEquals(f.mode, "wb") f.close() f = io.open(test_support.TESTFN, "U") @@ -1274,18 +1274,18 @@ class MiscIOTest(unittest.TestCase): self.assertEquals(f.buffer.name, test_support.TESTFN) self.assertEquals(f.buffer.raw.name, test_support.TESTFN) self.assertEquals(f.mode, "U") - self.assertEquals(f.buffer.mode, "r") - self.assertEquals(f.buffer.raw.mode, "r") + self.assertEquals(f.buffer.mode, "rb") + self.assertEquals(f.buffer.raw.mode, "rb") f.close() f = io.open(test_support.TESTFN, "w+") self.assertEquals(f.mode, "w+") - self.assertEquals(f.buffer.mode, "r+") # Does it really matter? - self.assertEquals(f.buffer.raw.mode, "r+") + self.assertEquals(f.buffer.mode, "rb+") # Does it really matter? + self.assertEquals(f.buffer.raw.mode, "rb+") g = io.open(f.fileno(), "wb", closefd=False) - self.assertEquals(g.mode, "w") - self.assertEquals(g.raw.mode, "w") + self.assertEquals(g.mode, "wb") + self.assertEquals(g.raw.mode, "wb") self.assertEquals(g.name, f.fileno()) self.assertEquals(g.raw.name, f.fileno()) f.close() @@ -56,6 +56,8 @@ Library - Issue #4363: The uuid.uuid1() and uuid.uuid4() functions now work even if the ctypes module is not present. +- FileIO's mode attribute now always includes ``"b"``. + - Issue #4116: Resolve member name conflict in ScrolledCanvas.__init__. - httplib.HTTPConnection.putheader() now accepts an arbitrary number of values diff --git a/Modules/_fileio.c b/Modules/_fileio.c index b9310f3..65cc99d 100644 --- a/Modules/_fileio.c +++ b/Modules/_fileio.c @@ -208,6 +208,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) flags |= O_CREAT; append = 1; break; + case 'b': + break; case '+': if (plus) goto bad_mode; @@ -682,12 +684,12 @@ mode_string(PyFileIOObject *self) { if (self->readable) { if (self->writable) - return "r+"; + return "rb+"; else - return "r"; + return "rb"; } else - return "w"; + return "wb"; } static PyObject * |