I was looking for some python help and hopefully you're still able and willing to answer some questions here, so I'll just post them and hope for the best 
I'm working on an IRC proxy (or bouncer) written in Python 3. In order to make certain things easier I've extended the socket class.
Code:
class IrcSocket(socket.socket):
def __init__(self, id):
self.id = id
socket.socket.__init__(self, socket.AF_INET, socket.SOCK_STREAM)
def send(self, bytes):
log(bytes)
socket.socket.sendall(self, bytes)
# etc (that's just a dummy)
However the server socket is a normal socket, and the socket.accept() function returns a normal socket... how can I turn this into an IrcSocket?
!!!
edit: Ignore the following question. I read the fucking manual. 
!!!
Since it's mainly running on windows, and is intended to only have a handful of connections, I'm using one thread for each connection. I'm using a dictionary of normal queues to pass messages between threads.
Code:
messages = {}
class IrcServer:
# __init__, etc
def handleMessage(self):
(type, data) = messages[self.id].get()
if type == 'ircChildren':
for (k, q) in enumerate(messages):
if k > self.id:
q.put(('irc', data))
# Other stuff
class IrcServerChild:
def __init__(self, id):
self.id = id
messages[id] = queue.Queue(0)
# Other stuff
However this fails with the error message
Code:
Exception in thread Thread-2:
Traceback (most recent call last)
File "C:\Python\lib\threading.py", line 736, in _bootstrap_inner
self.run()
File "C:\Users\khh\Documents\khh\python\kircp\src\ircserver.py", line 113, in run
IrcServer.handleMessage(self)
File "C:\Users\khh\Documents\khh\python\kircp\src\ircserver.py", line 141, in handleMessage
q.put(('irc', data))
AttributeError: 'int' object has no attribute 'put'
I don't get why q is an 'int' and not a 'Queue'.
Bookmarks