'Return current state object; set it first if `next_state` given.
Parameter `next_state`: a string, the name of the next state.
Exception: `UnknownStateError` raised if `next_state` unknown.'

def get_state(self, next_state=None):

    if next_state:
        if (self.debug and (next_state != self.current_state)):
            print >>sys.stderr, ('\nStateMachine.get_state:    Changing    state    from    "%s"    to    "%s"    (input    line    %s).' % (self.current_state, next_state, self.abs_line_number()))
        self.current_state = next_state
    try:
        return self.states[self.current_state]
    except KeyError:
        raise UnknownStateError(self.current_state)
