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

Pranav Devarakonda report at bugs.python.org
Thu Oct 4 10:45:00 EDT 2018


New submission from Pranav Devarakonda <devarakondapranav at yahoo.com>:

The send() method of the the Socket object in Python 3.x requires the data to be sent to be first converted into bytes(object) which was not the case with Python 2.x. The 2to3 tool doesn't handle this case and hence an explicit fixer would help many beginners learning the socket module(most tutorials regarding this online are in Python 2.x)

Similarly the fixer can change the recv() method by converting the returned bytes object back to a str object.
For example, consider the following lines in Python 2.x, (for demonstration only)

s.send("Foo") #where 's' is a socket object
data = s.recv(1024)

After the 2to3 fixer has been applied the above lines will change to,

s.send(str.encode("Foo"))
data = s.recv(1024).decode("utf-8")

PS: I am a beginner in open source so any changes or suggestions are welcome.

----------
components: 2to3 (2.x to 3.x conversion tool)
messages: 327053
nosy: benjamin.peterson, devarakondapranav
priority: normal
severity: normal
status: open
title: Add 2to3 fixer to change send and recv methods of socket object.
type: enhancement

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


More information about the Python-bugs-list mailing list