Cant overload python socket.send

Posted by ralu on Stack Overflow See other posts from Stack Overflow or by ralu
Published on 2010-05-14T09:21:21Z Indexed on 2010/05/14 9:24 UTC
Read the original article Hit count: 224

Filed under:
|
|

Code

from socket import socket

class PolySocket(socket):

    def __init__(self,*p):
        print "PolySocket init"
        socket.__init__(self,*p)

    def sendall(self,*p):
        print "PolySocket sendall"
        return socket.sendall(self,*p)

    def send(self,*p):
        print "PolySocket send"
        return socket.send(self,*p)


    def connect(self,*p):
        print "connecting..."
        socket.connect(self,*p)
        print "connected"

HOST="stackoverflow.com"   
PORT=80
readbuffer=""

s=PolySocket()
s.connect((HOST, PORT))
s.send("a")
s.sendall("a")

Output:

PolySocket init
connecting...
connected
PolySocket sendall

As we can see, send method is not overloaded.

© Stack Overflow or respective owner

Related posts about python

Related posts about inheritance