[Twisted-Python] How to cycle through servers on Connection Fail in an IRC client?

2021-02-25 Thread inhahe
I'm making an IRC client  using Twisted, and I want to connect to a
different server when connection fails, but I haven't been able to figure
out how to do that..

Here's a more or less minimal code sample reflecting what I have now:



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

class ServerConnection(irc.IRCClient):

  def __init__(self):
self.signedon = False
self.nickindex = 0

  def signedOn(self):
print("signed on")

  def nickChanged(self, newnick):
self.nickname = newnick

class Network(object):
  def __init__(self, servers, mynick=None):
self.servers = servers
self.mynick = mynick
self.serverindex = 0

class ServerFactory(protocol.ReconnectingClientFactory):
  def __init__(self, nickname="qttwirc", password=None, username="qttwirc",
realname=None, network=None):
self.network = network
self.network.mynick = nickname
self.nickname = nickname
self.username = username
self.password = password
self.realname = realname
protocol.ReconnectingClientFactory.initialDelay = 10 #should i leave
this at 1?
protocol.ReconnectingClientFactory.maxDelay = 10 #no idea what value
this should be. 3.5 wasn't slow enough, i was being throttled.

  def buildProtocol(self, addr):
p = ServerConnection()
self.serverconnection = p
p.server = self
p.nickname = self.nickname
p.username = self.username
self.resetDelay()
return p

  def clientConnectionLost(self, connector, reason):
self.serverconnection = None
protocol.ReconnectingClientFactory.clientConnectionLost(self,
connector, reason)

  def clientConnectionFailed(self, connector, reason):
self.serverconnection = None
addr, port = self.network.servers[self.network.serverindex]
self.network.serverindex = (self.network.serverindex+1) %
len(self.network.servers) #todo: make it actually use these values

#reactor.callLater(config.reconnectdelay, reactor.connectTCP,
addr.encode("ascii"), port, self)
#reactor.connectTCP(addr, port, self) #is this feasible? i don't know a
better way to do this. connector.connect() apparently doesn't take
server/port as arguments.

protocol.ReconnectingClientFactory.clientConnectionFailed(self,
connector, reason)

network = Network([("hitchcock.freenode.net", 6667), ("verne.freenode.net",
6667)])
server = ServerFactory(nickname="test123", username="test123",
network=network)
reactor.connectTCP(*network.servers[network.serverindex], server)
reactor.run()



If I have to completely change the structure of how I connect, that's
fine.. I don't understand Twisted very well, so I'm not aware of what some
other options are for how to make an IRC client.

(It probably doesn't matter, but in my actual program I'm using both
Twisted and PyQt5 in the same run loop using qt5reactor..)

Thanks.
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Twisted 21.2.0rc1 Release Candidate Announcement

2021-02-25 Thread Craig Rodrigues
On Mon, Feb 22, 2021 at 5:30 AM Richard van der Hoff 
wrote:

> As it happens, it also fails (for an import of typing.Deque) on Python
> 3.5.3, as used by Debian oldstable.
>
> Craig, what is your intention here? I think it's ok to drop support for
> these ancient versions of Python 3.5, but please could you make sure that
> python_requires gets set to 3.5.10 if that's what's been tested against?
>

Sigh.  I can confirm that typing.Deque does not import on Python 3.5.2.

I took an inventory of our CI, and realized that the minimum version we are
testing is *3.5.4* on Azure.

Can you review this which bumps the minimum version to Python 3.5.4:
https://github.com/twisted/twisted/pull/1525

Once I get that in, I will cherry pick it to the release branch and push
out the 21.2.0 release.

--
Craig
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python