Writing a blocking wrapper around twisted's IRC client
        Posted  
        
            by Andrey Fedorov
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Andrey Fedorov
        
        
        
        Published on 2010-04-22T01:21:08Z
        Indexed on 
            2010/04/22
            1:23 UTC
        
        
        Read the original article
        Hit count: 408
        
I'm trying to write a dead-simple interface for an IRC library, like so:
import simpleirc
connection = simpleirc.Connect('irc.freenode.net', 6667)
channel = connection.join('foo')
find_command = re.compile(r'google ([a-z]+)').findall
for msg in channel:
    for t in find_command(msg):
        channel.say("http://google.com/search?q=%s" % t)
Working from their example, I'm running into trouble (code is a bit lengthy, so I pasted it here). Since the call to channel.__next__ needs to be returned when the callback <IRCClient instance>.privmsg is called, there doesn't seem to be a clean option. Using exceptions or threads seems like the wrong thing here, is there a simpler (blocking?) way of using twisted that would make this possible?
© Stack Overflow or respective owner