It's kinda tough for me to help with this as I'm limited to coding in javascript at the moment. Hence I can't post running code.
It seems like it would be best to make IrcSocket a wrapper class that provides the necessary functionality using parasitic inheritance instead of classical inheritance. IIRC, socket.socket is a c class and things can get pretty hair extending those. Something like
Code:
class IrcSocket: #No need to extend object because this is p3k
def __init__(self, id, socket):
self.id = id
self._socket = socket
def send(self, bytes):
log(bytes)
socket.socket.sendall(self._socket, bytes)
Then you can get your hands on one with something like
Code:
ircsocket = IrcSocket(some_id, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
This just instantiates the socket inline and immiediately passes it to the IrcSocket class constructor.
You can just do
Code:
wrapped_socket = IrcSocket(some_id, socket.accept(*args))
to wrap the regular socket that socket.accept returns. Again, you're just making the call inline and passing it to the constructor.
Like I said, that's psuedocode because I can't run it and I don't have the library memorized but that's the basic idea.
Bookmarks