[Twisted-Python] clients with parameters

Konrad Rokicki konrad at wam.umd.edu
Wed Mar 19 22:50:12 EST 2003


Hi, got a quick question.
With any client where the __init__() method takes some parameters,
(i.e. FTPClient, TOCClient, etc), how can I use the connectTCP/factory
mechanisms and also pass it the parameters from the main program?
I started with this:

if __name__ == "__main__":
    config = {} # configuration is loaded into this
    fact = AIMFactory(config['nick'], config['password'])
    reactor.connectTCP(config['server'], config['port'], fact)

class AIMFactory(protocol.ClientFactory):
    protocol = AIM
    def __init__(self, nick, password):
        self.nick = nick
        self.password = password
    # etc

class AIM(toc.TOCClient):
    def __init__(self):
	""" I don't have access to the factory here
            so I don't know these parameters...
        """
        toc.TOCClient.__init__(self, username, password)

This is probably all wrong, and I guess the factory isn't a good
place for those parameters to be. But I have a configuration file that I
read into a structure and I want to use those options.

I looked at the ClientCreator which kind of does what I need but I'd
still like to have the factory for other things like logging. Actually,
I dont think I'll ever create more than one instance of the client, so I
could just use that, but I'd like to know the "right" way of doing this.

Thanks,
Konrad Rokicki





More information about the Twisted-Python mailing list