[New-bugs-announce] [issue31062] socket.makefile does not handle line buffering
Kevin Chen
report at bugs.python.org
Thu Jul 27 17:11:45 EDT 2017
New submission from Kevin Chen:
File objects generated with socket.makefile and that attempt to use line buffering appear to not actually use line buffering, at least for writing. In this example, the string does not appear to be written until the flush call.
First, set up a socket:
$ nc -l -U /tmp/foo
Then:
Python 3.6.2 (default, Jul 26 2017, 01:41:27)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
>>> s.connect("/tmp/foo")
>>> f = s.makefile("rw", buffering=1)
>>> f.write("asdf\n")
5
>>> f.flush()
The following patch appears to fix the problem:
--- socket.py.orig 2017-07-25 21:41:39.974554944 -0400
+++ socket.py 2017-07-27 17:02:58.223353418 -0400
@@ -253,7 +253,11 @@
buffer = io.BufferedWriter(raw, buffering)
if binary:
return buffer
- text = io.TextIOWrapper(buffer, encoding, errors, newline)
+ line_buffering = False
+ if buffering == 1:
+ line_buffering = True
+ text = io.TextIOWrapper(buffer, encoding, errors, newline,
+ line_buffering)
text.mode = mode
return text
----------
components: Library (Lib)
messages: 299351
nosy: kchen
priority: normal
severity: normal
status: open
title: socket.makefile does not handle line buffering
type: behavior
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31062>
_______________________________________
More information about the New-bugs-announce
mailing list