Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

sockets don't play nice with new style classes :(

54 views
Skip to first unread message

Paul Rubin

unread,
May 14, 2005, 5:22:19 AM5/14/05
to
Just a slight rant, I think I can find a workaround.

I wanted to trace all the output being sent through a socket:

from socket import *
sock = socket()
socket.connect((host, post))
socket.send('hello over there\n') # I want to log the string

Sounds like a job for new style classes:

class wsocket(socket):
def send(self, msg):
print 'socket sending (%s)'% repr(msg)
socket.send(msg)

sock = wsocket()
sock.connect(...)
# other stuff same as before

However, my print statement never got run.

After much head scratching it turns out that the library socket class
really makes a wrapper for an internal _socket.socket object. It goes
and manually sets the send and recv instance variables to the ones
from the _socket.socket, and does similar things for some other methods
and the doc strings.

It seems to me that the socket module itself should be rewritten to use
new style classes, so that socket.socket objects can extend _socket.socket
instead of wrapping them.

Am I missing something?

Skip Montanaro

unread,
May 14, 2005, 2:51:51 PM5/14/05
to Paul Rubin, pytho...@python.org

Paul> It seems to me that the socket module itself should be rewritten
Paul> to use new style classes, so that socket.socket objects can extend
Paul> _socket.socket instead of wrapping them.

Paul> Am I missing something?

Probably not. The socket module could use some attention.

Skip

0 new messages