[Twisted-Python] how to access irc.IRCClient.* from other classes

Nick Rehm speedy at nitroforce.eu
Mon Sep 4 15:57:36 EDT 2006


Hello,
iam playing around with twisted.words.irc and come upon this what i dont
understand right now

Here is a small example.

everything is working fine except the msg that should be send to the
channel.

from twisted.internet import protocol, reactor
from twisted.words.protocols import irc

class somestuff:

 def test(self):
    self.test = mainirc()
    self.test.test("#someircchannel","hi")
    #what i want to access here is 
    #irc.IRCClient.msg

class mainirc(irc.IRCClient):

  nickname = "twistedtest"

  def test(self,channel,msg):
     print channel
     print msg
     hold = channel
     hold2 = msg
     self.msg(hold,hold2)

  def connectionMade(self):
     irc.IRCClient.connectionMade(self)
     self.bot = somestuff()

  def joined(self,channel):
     print "joined"
     self.bot.test()

  def signedOn(self):
    self.join("#someircchannel")

class mainircFactory(protocol.ClientFactory):

  protocol = mainirc

  def clientConnectionLost(self,connector,reason):
    connector.connect()

  def clientConnectFailed(self,connector,reason):
    reactor.stop()

if __name__ == '__main__':
   f = mainircFactory()
   reactor.connectTCP("irc.someircserver.org",6667,f)
   reactor.run()



speeda at speeda:~$ python twistedirc.py
joined
#someircchannel
hi
Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/twisted/internet/tcp.py", line
348, in doRead
    return self.protocol.dataReceived(data)
  File
"/usr/lib/python2.4/site-packages/twisted/words/protocols/irc.py", line
1478, in dataReceived
    basic.LineReceiver.dataReceived(self, data.replace('\r', ''))
  File "/usr/lib/python2.4/site-packages/twisted/protocols/basic.py",
line 232, in dataReceived
    why = self.lineReceived(line)
  File
"/usr/lib/python2.4/site-packages/twisted/words/protocols/irc.py", line
1486, in lineReceived
    self.handleCommand(command, prefix, params)
--- <exception caught here> ---
  File
"/usr/lib/python2.4/site-packages/twisted/words/protocols/irc.py", line
1498, in handleCommand
    method(prefix, params)
  File
"/usr/lib/python2.4/site-packages/twisted/words/protocols/irc.py", line
1000, in irc_JOIN
    self.joined(channel)
  File "twistedirc.py", line 27, in joined
    self.bot.test()
  File "twistedirc.py", line 8, in test
    self.test.test("#tinyworlds","hi")
  File "twistedirc.py", line 19, in test
    self.msg(hold,hold2)
  File
"/usr/lib/python2.4/site-packages/twisted/words/protocols/irc.py", line
879, in msg
    self.sendLine(fmt % (message,))
  File
"/usr/lib/python2.4/site-packages/twisted/words/protocols/irc.py", line
572, in sendLine
    self._reallySendLine(line)
  File
"/usr/lib/python2.4/site-packages/twisted/words/protocols/irc.py", line
568, in _reallySendLine
    return basic.LineReceiver.sendLine(self, lowQuote(line) + '\r')
  File "/usr/lib/python2.4/site-packages/twisted/protocols/basic.py",
line 277, in sendLine
    return self.transport.write(line + self.delimiter)
exceptions.AttributeError: 'NoneType' object has no attribute 'write'

i hope someone can help me thanks in advance
Nick Rehm





More information about the Twisted-Python mailing list