Discussion:
[Python-3000-checkins] r67325 - in python/branches/py3k: Doc/library/stdtypes.rst Lib/socket.py Lib/test/test_fileio.py Lib/test/test_gzip.py Lib/test/test_io.py Lib/test/test_socket.py Misc/NEWS Modules/_fileio.c
benjamin.peterson
2008-11-22 00:41:46 UTC
Permalink
Author: benjamin.peterson
Date: Sat Nov 22 01:41:45 2008
New Revision: 67325

Log:
make FileIO.mode always include 'b'

#4386 Reviewed by Amaury


Modified:
python/branches/py3k/Doc/library/stdtypes.rst
python/branches/py3k/Lib/socket.py
python/branches/py3k/Lib/test/test_fileio.py
python/branches/py3k/Lib/test/test_gzip.py
python/branches/py3k/Lib/test/test_io.py
python/branches/py3k/Lib/test/test_socket.py
python/branches/py3k/Misc/NEWS
python/branches/py3k/Modules/_fileio.c

Modified: python/branches/py3k/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/py3k/Doc/library/stdtypes.rst (original)
+++ python/branches/py3k/Doc/library/stdtypes.rst Sat Nov 22 01:41:45 2008
@@ -1875,6 +1875,8 @@
view objects.


+.. _dict-views:
+
Dictionary view objects
-----------------------


Modified: python/branches/py3k/Lib/socket.py
==============================================================================
--- python/branches/py3k/Lib/socket.py (original)
+++ python/branches/py3k/Lib/socket.py Sat Nov 22 01:41:45 2008
@@ -198,10 +198,12 @@
# XXX More docs

def __init__(self, sock, mode):
- if mode not in ("r", "w", "rw"):
+ if mode not in ("r", "w", "rw", "rb", "wb", "rwb"):
raise ValueError("invalid mode: %r" % mode)
io.RawIOBase.__init__(self)
self._sock = sock
+ if "b" not in mode:
+ mode += "b"
self._mode = mode
self._reading = "r" in mode
self._writing = "w" in mode

Modified: python/branches/py3k/Lib/test/test_fileio.py
==============================================================================
--- python/branches/py3k/Lib/test/test_fileio.py (original)
+++ python/branches/py3k/Lib/test/test_fileio.py Sat Nov 22 01:41:45 2008
@@ -49,7 +49,7 @@
# 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
@@ -159,7 +159,7 @@

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:

Modified: python/branches/py3k/Lib/test/test_gzip.py
==============================================================================
--- python/branches/py3k/Lib/test/test_gzip.py (original)
+++ python/branches/py3k/Lib/test/test_gzip.py Sat Nov 22 01:41:45 2008
@@ -150,7 +150,7 @@
def test_mode(self):
self.test_write()
f = gzip.GzipFile(self.filename, 'r')
- self.assertTrue(f.myfileobj.mode.startswith('r'))
+ self.assertEqual(f.myfileobj.mode, 'rb')
f.close()

def test_1647484(self):

Modified: python/branches/py3k/Lib/test/test_io.py
==============================================================================
--- python/branches/py3k/Lib/test/test_io.py (original)
+++ python/branches/py3k/Lib/test/test_io.py Sat Nov 22 01:41:45 2008
@@ -1266,7 +1266,7 @@

def test_attributes(self):
f = io.open(support.TESTFN, "wb", buffering=0)
- self.assertEquals(f.mode, "w")
+ self.assertEquals(f.mode, "wb")
f.close()

f = io.open(support.TESTFN, "U")
@@ -1274,18 +1274,18 @@
self.assertEquals(f.buffer.name, support.TESTFN)
self.assertEquals(f.buffer.raw.name, 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(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()

Modified: python/branches/py3k/Lib/test/test_socket.py
==============================================================================
--- python/branches/py3k/Lib/test/test_socket.py (original)
+++ python/branches/py3k/Lib/test/test_socket.py Sat Nov 22 01:41:45 2008
@@ -849,11 +849,11 @@
self.assert_(not self.cli_file.closed)

def testAttributes(self):
- self.assertEqual(self.serv_file.mode, 'r')
+ self.assertEqual(self.serv_file.mode, 'rb')
self.assertEqual(self.serv_file.name, self.cli_conn.fileno())

def _testAttributes(self):
- self.assertEqual(self.cli_file.mode, 'w')
+ self.assertEqual(self.cli_file.mode, 'wb')
self.assertEqual(self.cli_file.name, self.serv_conn.fileno())

class UnbufferedFileObjectClassTestCase(FileObjectClassTestCase):

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Sat Nov 22 01:41:45 2008
@@ -48,6 +48,8 @@
Library
-------

+- FileIO's mode attribute now always includes ``"b"``.
+
- Issue #3799: Fix dbm.dumb to accept strings as well as bytes for keys. String
keys are now written out in UTF-8.


Modified: python/branches/py3k/Modules/_fileio.c
==============================================================================
--- python/branches/py3k/Modules/_fileio.c (original)
+++ python/branches/py3k/Modules/_fileio.c Sat Nov 22 01:41:45 2008
@@ -208,6 +208,8 @@
flags |= O_CREAT;
append = 1;
break;
+ case 'b':
+ break;
case '+':
if (plus)
goto bad_mode;
@@ -682,12 +684,12 @@
{
if (self->readable) {
if (self->writable)
- return "r+";
+ return "rb+";
else
- return "r";
+ return "rb";
}
else
- return "w";
+ return "wb";
}

static PyObject *

Loading...