[Twisted-Python] Sending commands when using Telnet client

Jean-Paul Calderone exarkun at divmod.com
Tue Feb 28 15:12:21 MST 2006


On Tue, 28 Feb 2006 10:59:50 -0800, Don Smith <donwsmith at gmail.com> wrote:
>Yes, I'm sort of a Twisted newbie, so maybe this has an obvious answer, but
>I'm just not seeing it.
>
>I have a Twisted program that I need to add in the ability to make a client
>telnet connection to a remote server and send some commands to it and deal
>with the data received.
>
> [snip]
>
>This all works great, except that the command sequence is hard coded in the
>TelnetClient class. I want to be able to reference the "cmd" parameter,
>which could be a list of commands to iterate over,etc. But I don't see how I
>can access the "cmd" parameter that gets passed into the TelnetConnection
>class from within the TelnetClient class.
>
>I'm really desparate for some help, I've been racking my brain on this since
>yesterday morning.

The usual approach is to save the data (`cmd' in this case) on the factory and use `self.factory.stuff' from the protocol.  The `factory' attribute is set on the protocol class by the default `buildProtocol' implementation.  It is not available in the protocol's `__init__', but is available by the time `connectionMade' is called.

Jean-Paul




More information about the Twisted-Python mailing list