[issue34893] Add 2to3 fixer to change send and recv methods of socket object.

Pranav Devarakonda report at bugs.python.org
Sat Oct 6 14:15:16 EDT 2018


Pranav Devarakonda <devarakondapranav at yahoo.com> added the comment:

Thanks for pointing out these cases. I kept in mind the Python 2 documentation which says socket.send method expects a string and hence made that fixer. I have tweaked that fixer to handle the pointed cases and a few additional ones too. Please find attached the updated fixer. To summarize, the following send() cases would not be changed,

data = "Data"
s.send(str.encode(data))
s.send(data.encode('utf-8))
s.send(bytes(data, 'utf-8'))
s.send(struct.pack('!I', x))

Similary, the following recv() cases would not be changed, 

data = s.recv(1024).decode('utf-8')
q, w, e = struct.unpack('!IHQ', s.recv(4))

The remaining generic cases will be handled as expected. I know we cannot handle cases where the data has already been converted to bytes(since there is no way to find the 'type' of the object here) and then sent as an argument to socket.send(). But if we have to go by the documentation, then this is probably the right thing to do.

----------
Added file: https://bugs.python.org/file47854/fix_socket_send_recv_updated.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34893>
_______________________________________


More information about the Python-bugs-list mailing list