(self, states, on_enter=None, on_exit=None,
                   ignore_invalid_triggers=None, **kwargs)
Add new state(s).
        Args:
            states (list, str, dict, Enum or State): a list, a State instance, the
                name of a new state, an enumeration (member) or a dict with keywords to pass on to the
                State initializer. If a list, each element can be a string, State or enumeration member.
            on_enter (str or list): callbacks to trigger when the state is
                entered. Only valid if first argument is string.
            on_exit (str or list): callbacks to trigger when the state is
                exited. Only valid if first argument is string.
            ignore_invalid_triggers: when True, any calls to trigger methods
                that are not valid for the present state (e.g., calling an
                a_to_b() trigger when the current state is c) will be silently
                ignored rather than raising an invalid transition exception.
                Note that this argument takes precedence over the same
                argument defined at the Machine level, and is in turn
                overridden by any ignore_invalid_triggers explicitly
                passed in an individual state's initialization arguments.

            **kwargs additional keyword arguments used by state mixins.
Add new state(s).
        Args:
            states (list, str, dict, Enum or State): a list, a State instance, the
                name of a new state, an enumeration (member) or a dict with keywords to pass on to the
                State initializer. If a list, each element can be a string, State or enumeration member.
            on_enter (str or list): callbacks to trigger when the state is
                entered. Only valid if first argument is string.
            on_exit (str or list): callbacks to trigger when the state is
                exited. Only valid if first argument is string.
            ignore_invalid_triggers: when True, any calls to trigger methods
                that are not valid for the present state (e.g., calling an
                a_to_b() trigger when the current state is c) will be silently
                ignored rather than raising an invalid transition exception.
                Note that this argument takes precedence over the same
                argument defined at the Machine level, and is in turn
                overridden by any ignore_invalid_triggers explicitly
                passed in an individual state's initialization arguments.
Add new state ( s ) . Args : states ( list str dict Enum or State ) : a list a State instance the name of a new state an enumeration ( member ) or a dict with keywords to pass on to the State initializer . If a list each element can be a string State or enumeration member . on_enter ( str or list ) : callbacks to trigger when the state is entered . Only valid if first argument is string . on_exit ( str or list ) : callbacks to trigger when the state is exited . Only valid if first argument is string . ignore_invalid_triggers : when True any calls to trigger methods that are not valid for the present state ( e . g . calling an a_to_b () trigger when the current state is c ) will be silently ignored rather than raising an invalid transition exception . Note that this argument takes precedence over the same argument defined at the Machine level and is in turn overridden by any ignore_invalid_triggers explicitly passed in an individual state s initialization arguments .
def add_states(self, states, on_enter=None, on_exit=None,
                   ignore_invalid_triggers=None, **kwargs):
        """ Add new state(s).
        Args:
            states (list, str, dict, Enum or State): a list, a State instance, the
                name of a new state, an enumeration (member) or a dict with keywords to pass on to the
                State initializer. If a list, each element can be a string, State or enumeration member.
            on_enter (str or list): callbacks to trigger when the state is
                entered. Only valid if first argument is string.
            on_exit (str or list): callbacks to trigger when the state is
                exited. Only valid if first argument is string.
            ignore_invalid_triggers: when True, any calls to trigger methods
                that are not valid for the present state (e.g., calling an
                a_to_b() trigger when the current state is c) will be silently
                ignored rather than raising an invalid transition exception.
                Note that this argument takes precedence over the same
                argument defined at the Machine level, and is in turn
                overridden by any ignore_invalid_triggers explicitly
                passed in an individual state's initialization arguments.

            **kwargs additional keyword arguments used by state mixins.
        """

        ignore = ignore_invalid_triggers
        if ignore is None:
            ignore = self.ignore_invalid_triggers

        states = listify(states)

        for state in states:
            if isinstance(state, (string_types, Enum)):
                state = self._create_state(
                    state, on_enter=on_enter, on_exit=on_exit,
                    ignore_invalid_triggers=ignore, **kwargs)
            elif isinstance(state, dict):
                if 'ignore_invalid_triggers' not in state:
                    state['ignore_invalid_triggers'] = ignore
                state = self._create_state(**state)
            self.states[state.name] = state
            for model in self.models:
                self._add_model_to_state(state, model)
            if self.auto_transitions:
                for a_state in self.states.keys():
                    # add all states as sources to auto transitions 'to_<state>' with dest <state>
                    if a_state == state.name:
                        if self.model_attribute == 'state':
                            method_name = 'to_%s' % a_state
                        else:
                            method_name = 'to_%s_%s' % (self.model_attribute, a_state)
                            self.add_transition('to_%s' % a_state, self.wildcard_all, a_state,
                                                prepare=partial(_warning_wrapper_to, 'to_%s' % a_state))
                        self.add_transition(method_name, self.wildcard_all, a_state)

                    # add auto transition with source <state> to <a_state>
                    else:
                        if self.model_attribute == 'state':
                            method_name = 'to_%s' % a_state
                        else:
                            method_name = 'to_%s_%s' % (self.model_attribute, a_state)
                            self.add_transition('to_%s' % a_state, state.name, a_state,
                                                prepare=partial(_warning_wrapper_to, 'to_%s' % a_state))
                        self.add_transition(method_name, state.name, a_state)
def add_states ( self , states , on_enter = None , on_exit = None , ignore_invalid_triggers = None , * * kwargs ) : ignore = ignore_invalid_triggers if ignore is None : ignore = self . ignore_invalid_triggers states = listify ( states ) for state in states : if isinstance ( state , ( string_types , Enum ) ) : state = self . _create_state ( state , on_enter = on_enter , on_exit = on_exit , ignore_invalid_triggers = ignore , * * kwargs ) elif isinstance ( state , dict ) : if 'ignore_invalid_triggers' not in state : state [ 'ignore_invalid_triggers' ] = ignore state = self . _create_state ( * * state ) self . states [ state . name ] = state for model in self . models : self . _add_model_to_state ( state , model ) if self . auto_transitions : for a_state in self . states . keys ( ) : # add all states as sources to auto transitions 'to_<state>' with dest <state> if a_state == state . name : if self . model_attribute == 'state' : method_name = 'to_%s' % a_state else : method_name = 'to_%s_%s' % ( self . model_attribute , a_state ) self . add_transition ( 'to_%s' % a_state , self . wildcard_all , a_state , prepare = partial ( _warning_wrapper_to , 'to_%s' % a_state ) ) self . add_transition ( method_name , self . wildcard_all , a_state ) # add auto transition with source <state> to <a_state> else : if self . model_attribute == 'state' : method_name = 'to_%s' % a_state else : method_name = 'to_%s_%s' % ( self . model_attribute , a_state ) self . add_transition ( 'to_%s' % a_state , state . name , a_state , prepare = partial ( _warning_wrapper_to , 'to_%s' % a_state ) ) self . add_transition ( method_name , state . name , a_state )