[Twisted-Python] I'm stuck

Jean-Paul Calderone exarkun at divmod.com
Tue May 6 10:17:32 EDT 2008


On Tue, 06 May 2008 09:56:22 -0400, Curt <curtferguson at cfl.rr.com> wrote:
>Ok, first, I'm a true newbie, I've been playing with twisted, and python
>for that matter, for about 3 days.  I've been trying to get this script
>to work, and I *know* I've got to be doing something simple wrong.  All
>it is, is a slap-together of various examples available in the twisted
>documentation to see if I can learn how this works.  Here's the script
>
>All it is supposed to do at this point is accept a normal telnet
>connection on one port and authenticate it, and an ssh on another, and
>authenticate, I'm attempting to write an interpreter to connect both
>inputs to, but right now I'm stuck getting the connections to hold.
>
>Any assistance would be most welcome.
>
> [snip]
>
>class parseInput(recvline.HistoricRecvLine):
>
>    def connectionMade(self):
>        print("Got Connection to parseInput")
>        recvline.HistoricRecvLine.connectionMade(self)
>        print("Came back from the undercall")
>        self.interpreter=commandInterpreter
>
>    def handle_QUIT(self):
>        self.terminal.loseConnection()
>
>    def lineReceived(self, line):
>        print("Input, " + line)
>        self.terminal.write("I got, " + line)
>
> [snip]
>
>    if options['telnetPort']:
>        telnetRealm = _BaseTelnetRealm(telnet.TelnetBootstrapProtocol,
>                                   insults.ServerProtocol,
>                                   parseInput,
>                                   namespace)
>
> [snip]

The first problem I notice is that where you're creating the realm,
you're indicating that `parseInput´ should be instantiated with one
positional argument, `namespace´.  However, `parseInput´ takes zero
arguments (beyond self) to its initializer.  This means a TypeError
will be raised when `insults.ServerProtocol´ tries to instantiate
`parseInput´.

You might find the --debug option to `twistd´ helpful in the short
term.  It will drop you into pdb when an unhandled exception happens
so that you can see where the problem occurs, what it is, and look
at the state of the process.

Longer term, unit tests are a great way to isolate failures and get
immediate feedback on whether or not a piece of code or a change to
some code works or not.

Good luck,

Jean-Paul




More information about the Twisted-Python mailing list