(self, model=self_literal, states=None, initial='initial', transitions=None,
                 send_event=False, auto_transitions=True,
                 ordered_transitions=False, ignore_invalid_triggers=None,
                 before_state_change=None, after_state_change=None, name=None,
                 queued=False, prepare_event=None, finalize_event=None, model_attribute='state', on_exception=None,
                 **kwargs)
Args:
            model (object or list): The object(s) whose states we want to manage. If set to `Machine.self_literal`
                (default value), the current Machine instance will be used as the model (i.e., all
                triggering events will be attached to the Machine itself). Note that an empty list
                is treated like no model.
            states (list or Enum): A list or enumeration of valid states. Each list element can be either a
                string, an enum member or a State instance. If string or enum member, a new generic State
                instance will be created that is named according to the string or enum member's name.
            initial (str, Enum or State): The initial state of the passed model[s].
            transitions (list): An optional list of transitions. Each element
                is a dictionary of named arguments to be passed onto the
                Transition initializer.
            send_event (boolean): When True, any arguments passed to trigger
                methods will be wrapped in an EventData object, allowing
                indirect and encapsulated access to data. When False, all
                positional and keyword arguments will be passed directly to all
                callback methods.
            auto_transitions (boolean): When True (default), every state will
                automatically have an associated to_{state}() convenience
                trigger in the base model.
            ordered_transitions (boolean): Convenience argument that calls
                add_ordered_transitions() at the end of initialization if set
                to True.
            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.
            before_state_change: A callable called on every change state before
                the transition happened. It receives the very same args as normal
                callbacks.
            after_state_change: A callable called on every change state after
                the transition happened. It receives the very same args as normal
                callbacks.
            name: If a name is set, it will be used as a prefix for logger output
            queued (boolean): When True, processes transitions sequentially. A trigger
                executed in a state callback function will be queued and executed later.
                Due to the nature of the queued processing, all transitions will
                _always_ return True since conditional checks cannot be conducted at queueing time.
            prepare_event: A callable called on for before possible transitions will be processed.
                It receives the very same args as normal callbacks.
            finalize_event: A callable called on for each triggered event after transitions have been processed.
                This is also called when a transition raises an exception.
            on_exception: A callable called when an event raises an exception. If not set,
                the exception will be raised instead.

            **kwargs additional arguments passed to next class in MRO. This can be ignored in most cases.
Args:
            model (object or list): The object(s) whose states we want to manage. If set to `Machine.self_literal`
                (default value), the current Machine instance will be used as the model (i.e., all
                triggering events will be attached to the Machine itself). Note that an empty list
                is treated like no model.
            states (list or Enum): A list or enumeration of valid states. Each list element can be either a
                string, an enum member or a State instance. If string or enum member, a new generic State
                instance will be created that is named according to the string or enum member's name.
            initial (str, Enum or State): The initial state of the passed model[s].
            transitions (list): An optional list of transitions. Each element
                is a dictionary of named arguments to be passed onto the
                Transition initializer.
            send_event (boolean): When True, any arguments passed to trigger
                methods will be wrapped in an EventData object, allowing
                indirect and encapsulated access to data. When False, all
                positional and keyword arguments will be passed directly to all
                callback methods.
            auto_transitions (boolean): When True (default), every state will
                automatically have an associated to_{state}() convenience
                trigger in the base model.
            ordered_transitions (boolean): Convenience argument that calls
                add_ordered_transitions() at the end of initialization if set
                to True.
            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.
            before_state_change: A callable called on every change state before
                the transition happened. It receives the very same args as normal
                callbacks.
            after_state_change: A callable called on every change state after
                the transition happened. It receives the very same args as normal
                callbacks.
            name: If a name is set, it will be used as a prefix for logger output
            queued (boolean): When True, processes transitions sequentially. A trigger
                executed in a state callback function will be queued and executed later.
                Due to the nature of the queued processing, all transitions will
                _always_ return True since conditional checks cannot be conducted at queueing time.
            prepare_event: A callable called on for before possible transitions will be processed.
                It receives the very same args as normal callbacks.
            finalize_event: A callable called on for each triggered event after transitions have been processed.
                This is also called when a transition raises an exception.
            on_exception: A callable called when an event raises an exception. If not set,
                the exception will be raised instead.
Args : model ( object or list ) : The object ( s ) whose states we want to manage . If set to Machine . self_literal ( default value ) the current Machine instance will be used as the model ( i . e . all triggering events will be attached to the Machine itself ) . Note that an empty list is treated like no model . states ( list or Enum ) : A list or enumeration of valid states . Each list element can be either a string an enum member or a State instance . If string or enum member a new generic State instance will be created that is named according to the string or enum member s name . initial ( str Enum or State ) : The initial state of the passed model [ s ] . transitions ( list ) : An optional list of transitions . Each element is a dictionary of named arguments to be passed onto the Transition initializer . send_event ( boolean ) : When True any arguments passed to trigger methods will be wrapped in an EventData object allowing indirect and encapsulated access to data . When False all positional and keyword arguments will be passed directly to all callback methods . auto_transitions ( boolean ) : When True ( default ) every state will automatically have an associated to_ { state } () convenience trigger in the base model . ordered_transitions ( boolean ) : Convenience argument that calls add_ordered_transitions () at the end of initialization if set to True . 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 . before_state_change : A callable called on every change state before the transition happened . It receives the very same args as normal callbacks . after_state_change : A callable called on every change state after the transition happened . It receives the very same args as normal callbacks . name : If a name is set it will be used as a prefix for logger output queued ( boolean ) : When True processes transitions sequentially . A trigger executed in a state callback function will be queued and executed later . Due to the nature of the queued processing all transitions will _always_ return True since conditional checks cannot be conducted at queueing time . prepare_event : A callable called on for before possible transitions will be processed . It receives the very same args as normal callbacks . finalize_event : A callable called on for each triggered event after transitions have been processed . This is also called when a transition raises an exception . on_exception : A callable called when an event raises an exception . If not set the exception will be raised instead .
def __init__(self, model=self_literal, states=None, initial='initial', transitions=None,
                 send_event=False, auto_transitions=True,
                 ordered_transitions=False, ignore_invalid_triggers=None,
                 before_state_change=None, after_state_change=None, name=None,
                 queued=False, prepare_event=None, finalize_event=None, model_attribute='state', on_exception=None,
                 **kwargs):
        """
        Args:
            model (object or list): The object(s) whose states we want to manage. If set to `Machine.self_literal`
                (default value), the current Machine instance will be used as the model (i.e., all
                triggering events will be attached to the Machine itself). Note that an empty list
                is treated like no model.
            states (list or Enum): A list or enumeration of valid states. Each list element can be either a
                string, an enum member or a State instance. If string or enum member, a new generic State
                instance will be created that is named according to the string or enum member's name.
            initial (str, Enum or State): The initial state of the passed model[s].
            transitions (list): An optional list of transitions. Each element
                is a dictionary of named arguments to be passed onto the
                Transition initializer.
            send_event (boolean): When True, any arguments passed to trigger
                methods will be wrapped in an EventData object, allowing
                indirect and encapsulated access to data. When False, all
                positional and keyword arguments will be passed directly to all
                callback methods.
            auto_transitions (boolean): When True (default), every state will
                automatically have an associated to_{state}() convenience
                trigger in the base model.
            ordered_transitions (boolean): Convenience argument that calls
                add_ordered_transitions() at the end of initialization if set
                to True.
            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.
            before_state_change: A callable called on every change state before
                the transition happened. It receives the very same args as normal
                callbacks.
            after_state_change: A callable called on every change state after
                the transition happened. It receives the very same args as normal
                callbacks.
            name: If a name is set, it will be used as a prefix for logger output
            queued (boolean): When True, processes transitions sequentially. A trigger
                executed in a state callback function will be queued and executed later.
                Due to the nature of the queued processing, all transitions will
                _always_ return True since conditional checks cannot be conducted at queueing time.
            prepare_event: A callable called on for before possible transitions will be processed.
                It receives the very same args as normal callbacks.
            finalize_event: A callable called on for each triggered event after transitions have been processed.
                This is also called when a transition raises an exception.
            on_exception: A callable called when an event raises an exception. If not set,
                the exception will be raised instead.

            **kwargs additional arguments passed to next class in MRO. This can be ignored in most cases.
        """

        # calling super in case `Machine` is used as a mix in
        # all keyword arguments should be consumed by now if this is not the case
        try:
            super(Machine, self).__init__(**kwargs)
        except TypeError as err:
            raise ValueError('Passing arguments {0} caused an inheritance error: {1}'.format(kwargs.keys(), err))

        # initialize protected attributes first
        self._queued = queued
        self._transition_queue = deque()
        self._before_state_change = []
        self._after_state_change = []
        self._prepare_event = []
        self._finalize_event = []
        self._on_exception = []
        self._initial = None

        self.states = OrderedDict()
        self.events = {}
        self.send_event = send_event
        self.auto_transitions = auto_transitions
        self.ignore_invalid_triggers = ignore_invalid_triggers
        self.prepare_event = prepare_event
        self.before_state_change = before_state_change
        self.after_state_change = after_state_change
        self.finalize_event = finalize_event
        self.on_exception = on_exception
        self.name = name + ": " if name is not None else ""
        self.model_attribute = model_attribute

        self.models = []

        if states is not None:
            self.add_states(states)

        if initial is not None:
            self.initial = initial

        if transitions is not None:
            self.add_transitions(transitions)

        if ordered_transitions:
            self.add_ordered_transitions()

        if model:
            self.add_model(model)
def __init__ ( self , model = self_literal , states = None , initial = 'initial' , transitions = None , send_event = False , auto_transitions = True , ordered_transitions = False , ignore_invalid_triggers = None , before_state_change = None , after_state_change = None , name = None , queued = False , prepare_event = None , finalize_event = None , model_attribute = 'state' , on_exception = None , * * kwargs ) : # calling super in case `Machine` is used as a mix in # all keyword arguments should be consumed by now if this is not the case try : super ( Machine , self ) . __init__ ( * * kwargs ) except TypeError as err : raise ValueError ( 'Passing arguments {0} caused an inheritance error: {1}' . format ( kwargs . keys ( ) , err ) ) # initialize protected attributes first self . _queued = queued self . _transition_queue = deque ( ) self . _before_state_change = [ ] self . _after_state_change = [ ] self . _prepare_event = [ ] self . _finalize_event = [ ] self . _on_exception = [ ] self . _initial = None self . states = OrderedDict ( ) self . events = { } self . send_event = send_event self . auto_transitions = auto_transitions self . ignore_invalid_triggers = ignore_invalid_triggers self . prepare_event = prepare_event self . before_state_change = before_state_change self . after_state_change = after_state_change self . finalize_event = finalize_event self . on_exception = on_exception self . name = name + ": " if name is not None else "" self . model_attribute = model_attribute self . models = [ ] if states is not None : self . add_states ( states ) if initial is not None : self . initial = initial if transitions is not None : self . add_transitions ( transitions ) if ordered_transitions : self . add_ordered_transitions ( ) if model : self . add_model ( model )