• Lucid Dreaming - Dream Views




    Results 1 to 25 of 28
    Like Tree2Likes

    Thread: Ask me about Python

    Threaded View

    1. #22
      khh
      khh is offline
      Remember Achievements:
      1000 Hall Points Veteran First Class
      khh's Avatar
      Join Date
      Jun 2009
      Gender
      Location
      Norway
      Posts
      2,482
      Likes
      1309
      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'.
      Last edited by khh; 07-19-2011 at 12:11 PM.
      April Ryan is my friend,
      Every sorrow she can mend.
      When i visit her dark realm,
      Does it simply overwhelm.

    Similar Threads

    1. Pass Variables Between JavaScript and C++/Python?
      By youssarian in forum Tech Talk
      Replies: 6
      Last Post: 01-12-2010, 04:27 AM
    2. Halp! (Python)
      By ThreeLetterSyndrom in forum Tech Talk
      Replies: 5
      Last Post: 06-23-2009, 09:43 PM
    3. Tell me about Python
      By DuB in forum Tech Talk
      Replies: 9
      Last Post: 04-29-2009, 04:55 PM
    4. Python Reality Check Tester
      By Wesley_Gray in forum Lucid Aids
      Replies: 10
      Last Post: 08-01-2008, 02:16 AM
    5. Fav Python Quotes
      By Mystical_Journey in forum The Lounge
      Replies: 20
      Last Post: 05-12-2005, 09:50 PM

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •