Message118161
my bad for not rtfm, but it seems the newline argument has no effect in socket.makefile.
the TextIOWrapper signatures don't seem to match. a hack to put newline parameter in 4th position or making it a keyword arg doesn't work either (scratch my head...)
socket.py source <line 162>
text = io.TextIOWrapper(buffer, encoding, newline)
textio.c <line 807>
static int
textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
{
char *kwlist[] = {"buffer", "encoding", "errors",
"newline", "line_buffering",
NULL};
$ python3 echo.py ## from previous example
$ python3 client.py
b'hello\r\n' recv()
b'hello\r\n' makefile(mode = "rb")
'hello\n' makefile(mode = "r", newline = "")
# echo client program
data = b'hello\r\n'
import socket
clie = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
clie.connect(('localhost', 12345))
clie.send(data)
data = clie.recv(4096)
print(repr(data), 'recv()')
clie.send(data)
file = clie.makefile('rb')
data = file.readline()
print(repr(data), 'makefile(mode = "rb")')
clie.send(data)
file = clie.makefile('r', newline = '')
data = file.readline()
print(repr(data), 'makefile(mode = "r", newline = "")') ## '\r' is still silently dropped
finally:
clie.close() |
|
Date |
User |
Action |
Args |
2010-10-08 03:24:48 | kaizhu | set | recipients:
+ kaizhu, pitrou, eric.smith |
2010-10-08 03:24:47 | kaizhu | set | messageid: <1286508287.93.0.0400254171427.issue10041@psf.upfronthosting.co.za> |
2010-10-08 03:24:46 | kaizhu | link | issue10041 messages |
2010-10-08 03:24:45 | kaizhu | create | |
|