cpython: a7391c31ec4e (original) (raw)
Mercurial > cpython
changeset 100260:a7391c31ec4e 3.5
Issue #16915: Clarify that mode parameter of socket.makefile() does not accept the same values as open(). [#16915]
Berker Peksag berker.peksag@gmail.com | |
---|---|
date | Thu, 18 Feb 2016 17:34:00 +0200 |
parents | 651a6d47bc78 |
children | bbfbde6ee9d0 537608bafa5a |
files | Doc/library/socket.rst Lib/socket.py Lib/test/test_socket.py |
diffstat | 3 files changed, 19 insertions(+), 4 deletions(-)[+] [-] Doc/library/socket.rst 3 Lib/socket.py 6 Lib/test/test_socket.py 14 |
line wrap: on
line diff
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -1006,7 +1006,8 @@ to sockets.
Return a :term:file object
associated with the socket. The exact returned
type depends on the arguments given to :meth:makefile
. These arguments are
- interpreted the same way as by the built-in :func:
open
function, except - the only supported mode values are
'r'
(default),'w'
and'b'
. The socket must be in blocking mode; it can have a timeout, but the file object's internal buffer may end up in an inconsistent state if a timeout
--- a/Lib/socket.py +++ b/Lib/socket.py @@ -209,10 +209,10 @@ class socket(_socket.socket): encoding=None, errors=None, newline=None): """makefile(...) -> an I/O stream connected to the socket
The arguments are as for io.open() after the filename,[](#l2.7)
except the only mode characters supported are 'r', 'w' and 'b'.[](#l2.8)
The semantics are similar too. (XXX refactor to share code?)[](#l2.9)
The arguments are as for io.open() after the filename, except the only[](#l2.10)
supported mode values are 'r' (default), 'w' and 'b'.[](#l2.11) """[](#l2.12)
# XXX refactor to share code?[](#l2.13) if not set(mode) <= {"r", "w", "b"}:[](#l2.14) raise ValueError("invalid mode %r (only r, w, b allowed)" % (mode,))[](#l2.15) writing = "w" in mode[](#l2.16)
--- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1374,6 +1374,20 @@ class GeneralModuleTests(unittest.TestCa self.assertRaises(ValueError, fp.writable) self.assertRaises(ValueError, fp.seekable)
- def test_makefile_mode(self):
for mode in 'r', 'rb', 'rw', 'w', 'wb':[](#l3.8)
with self.subTest(mode=mode):[](#l3.9)
with socket.socket() as sock:[](#l3.10)
with sock.makefile(mode) as fp:[](#l3.11)
self.assertEqual(fp.mode, mode)[](#l3.12)