Message224053
Currently, the C module _socket has an useful representation of socket: it gives the file descriptor, family, type, etc. The Python socket module only shows the memory address. Example:
$ ./python -c 'import _socket; s=_socket.socket(); print(repr(s));'
<socket object, fd=3, family=2, type=1, protocol=0>
$ ./python -c 'import socket; s=socket.socket(); print(repr(s));'
<socket._socketobject object at 0x7fad1fdcbba0>
I propose to backport repr(socket.socket) from Python 3.5 to Python 2.7. With the patch, the Python socket even contains *more* information than the C module (laddr and raddr). Example with the patch applied:
$ ./python -c 'import socket; s=socket.socket(); print(repr(s));'
<socket._socketobject fd=3, family=2, type=1, proto=0, laddr=('0.0.0.0', 0)>
In Python 2.7, when a socket is closed, it drops the underlying C _socket object. So it's not possible to provide a better representation than:
$ ./python -c 'import socket; s=socket.socket(); s.close(); print(repr(s));'
<socket._socketobject[closed]>
I don't want to change the design of the Python module, Python 2.7 is very stable. I don't want to take the risk of breaking anything. |
|
Date |
User |
Action |
Args |
2014-07-26 13:06:02 | vstinner | set | recipients:
+ vstinner |
2014-07-26 13:06:02 | vstinner | set | messageid: <1406379962.85.0.838709000205.issue22081@psf.upfronthosting.co.za> |
2014-07-26 13:06:02 | vstinner | link | issue22081 messages |
2014-07-26 13:06:02 | vstinner | create | |
|