Message118095
i'm working on an independent py2to3 utility which directly imports py2x modules, by reverse compiling ast trees (code.google.com/p/asciiporn/source/browse/stable.py)
while forward porting the python2x redis client, this issue came up.
i kno its bad to use strings in sockets, but it seems webapps use it exploiting the fact utf8 is becoming a defacto web 'binary' standard
$ python3.1 echo.py
connected <socket.socket object, fd=4, family=2, type=1, proto=0> ('127.0.0.1', 41115)
$ python3.1 client.py
b'hello\r\n' recv()
b'hello\r\n' makefile(mode = "rb")
'hello\n' makefile(mode = "r")
## echo.py - echo server program
import socket
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
serv.bind(('localhost', 12345))
serv.listen(1)
while True:
conn, addr = serv.accept()
print( 'connected', conn, addr )
while True:
data = conn.recv(4096)
if not data:
conn.close()
break
conn.send(data)
finally:
serv.close()
## client.py - 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')
data = file.readline()
print(repr(data), 'makefile(mode = "r")') ## '\r' is silently dropped
finally:
clie.close() |
|
Date |
User |
Action |
Args |
2010-10-07 08:13:00 | kaizhu | set | recipients:
+ kaizhu |
2010-10-07 08:12:59 | kaizhu | set | messageid: <1286439179.94.0.684121251448.issue10041@psf.upfronthosting.co.za> |
2010-10-07 08:12:57 | kaizhu | link | issue10041 messages |
2010-10-07 08:12:56 | kaizhu | create | |
|