[Twisted-Python] Getting factory with AuthenticatingTelnetProtocol
Lucas Taylor
ltaylor.volks at gmail.com
Sat Feb 27 17:43:48 MST 2010
On 2/27/10 6:19 AM, Skye wrote:
> Hello,
>
> I used the code from this thread to figure out how to use
> the twisted.conch.telnet.AuthenticatingTelnetProtocol class:
>
> http://www.mail-archive.com/twisted-python@twistedmatrix.com/msg01581.html
>
> (with the addition of av.state = 'Command' in requestAvatar(), it works great)
>
> However, after the handoff to the new protocol MyTelnet, self.factory
> isn't set. How can I pass along the parent factory from the
> AuthenticatingTelnetProtocol instance to the StatefulTelnetProtocol instance?
>
> Sorry if this isn't phrased correctly - I'm new to Twisted.
>
> Thanks,
> Skye
>
Rather than pass it around, you could set the factory instance as an
attribute of the transport:
f = protocol.ServerFactory()
f.protocol = lambda: TelnetTransport(AuthenticatingTelnetProtocol, p)
f.protocol.factory = f
then the factory will be available from MyTelnet.transport:
class MyTelnet(StatefulTelnetProtocol):
def telnet_Command(self, line):
print "line received via telnet", line
print "The Server factory is a: %s" % (self.transport.factory)
Lucas
More information about the Twisted-Python
mailing list