pexpect/pexpect — pull request #89 by dcoshea (2014-07-08 05:03:11+00:00)
Title: Issue #85: Don't leave unwanted numbers in ANSI FSM stack/memory.

The FSM transitions set up by ANSI accept a number of escape sequences
that accept one or more numeric parameters where the escape sequence
as a whole is ignored (no action is executed at the end of the
sequence). This means that the numeric parameters are left on the
FSM's stack, making it harder to improve or subclass ANSI to handle
any of the sequences that take multiple numeric parameters, where it
is necessary to look at the entire stack rather than just, say, pop
one element off the top of the stack.

This fix sets up handlers that discard all items on the stack other
than the bottom-most, which is a reference to the ANSI instance
itself. The handlers are created as members of ANSI, rather than
methods in the ANSI package, so that they can be overridden in
subclasses without needing to replace FSM transitions.

A unit test is added to verify the new behavior, and the existing
test_number_x() unit test is modified to no longer expect the
parameters to be left on the stack after parsing, and instead use a
subclass of ANSI to capture them.