def _handle_action(self, action):

    def handle_single(a):
        if (type(a) == Macro):
            self._run_macro(a.code)
        elif (type(a) == Command):
            self._send_command(a.command)
        elif (type(a) == Exception):
            raise a
        else:
            raise Exception('Internal Error: invalid action type. Should be Macro, Command or Exception')
    if (type(action) == tuple):
        for a in action:
            handle_single(a)
    else:
        handle_single(action)
def _handle_action(self, action):

    def handle_single(a):
        if (type(a) == Macro):
            self._run_macro(a.code)
        elif (type(a) == Command):
            self._send_command(a.command)
        elif (type(a) == Exception):
            raise a
        else:
            raise Exception('Internal Error: invalid action type. Should be Macro, Command or Exception')
    if (type(action) == tuple):
        for a in action:
            handle_single(a)
    else:
        handle_single(action)