本文整理汇总了Python中machinist.TransitionTable类的典型用法代码示例。如果您正苦于以下问题:Python TransitionTable类的具体用法?Python TransitionTable怎么用?Python TransitionTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TransitionTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_convergence_loop_fsm
def build_convergence_loop_fsm(reactor, deployer):
"""
Create a convergence loop FSM.
:param IReactorTime reactor: Used to schedule delays in the loop.
:param IDeployer deployer: Used to discover local state and calcualte
necessary changes to match desired configuration.
"""
I = ConvergenceLoopInputs
O = ConvergenceLoopOutputs
S = ConvergenceLoopStates
table = TransitionTable()
table = table.addTransition(
S.STOPPED, I.STATUS_UPDATE, [O.STORE_INFO, O.CONVERGE], S.CONVERGING)
table = table.addTransitions(
S.CONVERGING, {
I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
I.STOP: ([], S.CONVERGING_STOPPING),
I.ITERATION_DONE: ([O.CONVERGE], S.CONVERGING),
})
table = table.addTransitions(
S.CONVERGING_STOPPING, {
I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
I.ITERATION_DONE: ([], S.STOPPED),
})
loop = ConvergenceLoop(reactor, deployer)
fsm = constructFiniteStateMachine(
inputs=I, outputs=O, states=S, initial=S.STOPPED, table=table,
richInputs=[_ClientStatusUpdate], inputContext={},
world=MethodSuffixOutputer(loop))
loop.fsm = fsm
return fsm
示例2: _build_convergence_loop_table
def _build_convergence_loop_table():
"""
Create the ``TransitionTable`` needed by the convergence loop FSM.
:return TransitionTable: The transition table for the state machine for
converging on the cluster configuration.
"""
I = ConvergenceLoopInputs
O = ConvergenceLoopOutputs
S = ConvergenceLoopStates
table = TransitionTable()
table = table.addTransition(
S.STOPPED, I.STATUS_UPDATE, [O.STORE_INFO, O.CONVERGE], S.CONVERGING)
table = table.addTransitions(
S.CONVERGING, {
I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
I.STOP: ([], S.CONVERGING_STOPPING),
I.SLEEP: ([O.SCHEDULE_WAKEUP], S.SLEEPING),
})
table = table.addTransitions(
S.CONVERGING_STOPPING, {
I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
I.SLEEP: ([], S.STOPPED),
})
table = table.addTransitions(
S.SLEEPING, {
I.WAKEUP: ([O.CLEAR_WAKEUP, O.CONVERGE], S.CONVERGING),
I.STOP: ([O.CLEAR_WAKEUP], S.STOPPED),
I.STATUS_UPDATE: (
[O.STORE_INFO, O.UPDATE_MAYBE_WAKEUP], S.SLEEPING),
})
return table
示例3: build_cluster_status_fsm
def build_cluster_status_fsm(convergence_loop_fsm):
"""
Create a new cluster status FSM.
The automatic reconnection logic is handled by the
``AgentLoopService``; the world object here just gets notified of
disconnects, it need schedule the reconnect itself.
:param convergence_loop_fsm: A convergence loop FSM as output by
``build_convergence_loop_fsm``.
"""
S = ClusterStatusStates
I = ClusterStatusInputs
O = ClusterStatusOutputs
table = TransitionTable()
# We may be shut down in any state, in which case we disconnect if
# necessary.
table = table.addTransitions(
S.DISCONNECTED,
{
# Store the client, then wait for cluster status to be sent
# over AMP:
I.CONNECTED_TO_CONTROL_SERVICE: ([O.STORE_CLIENT], S.IGNORANT),
I.SHUTDOWN: ([], S.SHUTDOWN),
},
)
table = table.addTransitions(
S.IGNORANT,
{
# We never told agent to start, so no need to tell it to stop:
I.DISCONNECTED_FROM_CONTROL_SERVICE: ([], S.DISCONNECTED),
# Tell agent latest cluster status, implicitly starting it:
I.STATUS_UPDATE: ([O.UPDATE_STATUS], S.KNOWLEDGEABLE),
I.SHUTDOWN: ([O.DISCONNECT], S.SHUTDOWN),
},
)
table = table.addTransitions(
S.KNOWLEDGEABLE,
{
# Tell agent latest cluster status:
I.STATUS_UPDATE: ([O.UPDATE_STATUS], S.KNOWLEDGEABLE),
I.DISCONNECTED_FROM_CONTROL_SERVICE: ([O.STOP], S.DISCONNECTED),
I.SHUTDOWN: ([O.STOP, O.DISCONNECT], S.SHUTDOWN),
},
)
table = table.addTransitions(
S.SHUTDOWN, {I.DISCONNECTED_FROM_CONTROL_SERVICE: ([], S.SHUTDOWN), I.STATUS_UPDATE: ([], S.SHUTDOWN)}
)
return constructFiniteStateMachine(
inputs=I,
outputs=O,
states=S,
initial=S.DISCONNECTED,
table=table,
richInputs=[_ConnectedToControlService, _StatusUpdate],
inputContext={},
world=MethodSuffixOutputer(ClusterStatus(convergence_loop_fsm)),
)
示例4: test_addTerminalState
def test_addTerminalState(self):
"""
L{TransitionTable.addTerminalState} returns a L{TransitionTable} that
includes the given state in its table with no transitions defined.
"""
table = TransitionTable()
more = table.addTerminalState("foo")
self.assertEqual({"foo": {}}, more.table)
示例5: test_addTransitionsDoesNotMutate
def test_addTransitionsDoesNotMutate(self):
"""
L{TransitionTable.addTransitions} does not change the
L{TransitionTable} it is called on.
"""
table = TransitionTable({"foo": {"bar": Transition("baz", "quux")}})
table.addTransitions("apple", {"banana": ("clementine", "date")})
self.assertEqual({"foo": {"bar": Transition("baz", "quux")}}, table.table)
示例6: test_addTransition
def test_addTransition(self):
"""
L{TransitionTable.addTransition} accepts a state, an input, an output,
and a next state and adds the transition defined by those four values
to a new L{TransitionTable} which it returns.
"""
table = TransitionTable()
more = table.addTransition("foo", "bar", "baz", "quux")
self.assertEqual({"foo": {"bar": Transition("baz", "quux")}}, more.table)
示例7: test_nextStateNotMissingIfInitial
def test_nextStateNotMissingIfInitial(self):
"""
L{MissingTransitionNextState} is not raised if a value defined by
C{state} appears nowhere in C{transitions} as a next state but is given
as C{initial}.
"""
transitions = TransitionTable()
transitions = transitions.addTransition(
MoreState.amber, Input.apple, [Output.aardvark], MoreState.amber)
transitions = transitions.addTerminalState(MoreState.blue)
constructFiniteStateMachine(
Input, Output, MoreState, transitions,
MoreState.blue, [], {}, NULL_WORLD)
示例8: test_invalidInitialState
def test_invalidInitialState(self):
"""
L{InvalidInitialState} is raised if the value given for C{initial} is
not defined by C{state}.
"""
extra = object()
transitions = TransitionTable()
transitions = transitions.addTransition(
State.amber, Input.apple, [Output.aardvark], State.amber)
exc = self.assertRaises(
InvalidInitialState,
constructFiniteStateMachine,
Input, Output, State, transitions,
extra, [], {}, NULL_WORLD)
self.assertEqual((extra,), exc.args)
示例9: test_extraInputContext
def test_extraInputContext(self):
"""
L{ExtraInputContext} is raised if there are keys in C{inputContext}
which are not symbols in the output alphabet.
"""
extra = object()
transitions = TransitionTable()
transitions = transitions.addTransition(
State.amber, Input.apple, [Output.aardvark], State.amber)
exc = self.assertRaises(
ExtraInputContext,
constructFiniteStateMachine,
Input, Output, State, transitions,
State.amber, [], {extra: None}, NULL_WORLD)
self.assertEqual(({extra},), exc.args)
示例10: test_addTransitions
def test_addTransitions(self):
"""
L{TransitionTable.addTransitions} accepts a state and a mapping from
inputs to output, next state pairs and adds all of those transitions to
the given state to a new L{TransitionTable} which it returns.
"""
table = TransitionTable()
more = table.addTransitions(
"apple", {
"banana": ("clementine", "date"),
"eggplant": ("fig", "grape")})
self.assertEqual(
{"apple": {
"banana": Transition("clementine", "date"),
"eggplant": Transition("fig", "grape")}},
more.table)
示例11: test_missingTransitionNextState
def test_missingTransitionNextState(self):
"""
L{MissingTransitionNextState} is raised if any of the values defined by
C{state} appears nowhere in C{transitions} as a next state.
"""
transitions = TransitionTable()
transitions = transitions.addTransition(
MoreState.amber, Input.apple, [Output.aardvark], MoreState.amber)
transitions = transitions.addTerminalState(MoreState.blue)
exc = self.assertRaises(
MissingTransitionNextState,
constructFiniteStateMachine,
Input, Output, MoreState, transitions,
MoreState.amber, [], {}, NULL_WORLD)
self.assertEqual(({MoreState.blue},), exc.args)
示例12: test_richInputInterface
def test_richInputInterface(self):
"""
L{DoesNotImplement} is raised if a rich input type is given which does
not implement the interface required by one of the outputs which can be
produced when that input is received.
"""
apple = trivialInput(Input.apple)
transitions = TransitionTable()
transitions = transitions.addTransition(
State.amber, Input.apple, [Output.aardvark], State.amber)
self.assertRaises(
DoesNotImplement,
constructFiniteStateMachine,
Input, Output, State, transitions,
State.amber, [apple], {Output.aardvark: IRequiredByAardvark},
NULL_WORLD)
示例13: _build_cluster_status_fsm_table
def _build_cluster_status_fsm_table():
"""
Create the ``TransitionTable`` needed by the cluster status FSM.
:return TransitionTable: The transition table for the state machine for
keeping track of cluster state and configuration.
"""
S = ClusterStatusStates
I = ClusterStatusInputs
O = ClusterStatusOutputs
table = TransitionTable()
# We may be shut down in any state, in which case we disconnect if
# necessary.
table = table.addTransitions(
S.DISCONNECTED, {
# Store the client, then wait for cluster status to be sent
# over AMP:
I.CONNECTED_TO_CONTROL_SERVICE: ([O.STORE_CLIENT], S.IGNORANT),
I.SHUTDOWN: ([], S.SHUTDOWN),
})
table = table.addTransitions(
S.IGNORANT, {
# We never told agent to start, so no need to tell it to stop:
I.DISCONNECTED_FROM_CONTROL_SERVICE: ([], S.DISCONNECTED),
# Tell agent latest cluster status, implicitly starting it:
I.STATUS_UPDATE: ([O.UPDATE_STATUS], S.KNOWLEDGEABLE),
I.SHUTDOWN: ([O.DISCONNECT], S.SHUTDOWN),
})
table = table.addTransitions(
S.KNOWLEDGEABLE, {
# Tell agent latest cluster status:
I.STATUS_UPDATE: ([O.UPDATE_STATUS], S.KNOWLEDGEABLE),
I.DISCONNECTED_FROM_CONTROL_SERVICE: ([O.STOP], S.DISCONNECTED),
I.SHUTDOWN: ([O.STOP, O.DISCONNECT], S.SHUTDOWN),
})
table = table.addTransitions(
S.SHUTDOWN, {
I.DISCONNECTED_FROM_CONTROL_SERVICE: ([], S.SHUTDOWN),
I.STATUS_UPDATE: ([], S.SHUTDOWN),
})
return table
示例14: NamedConstant
ARM_LOCKED = NamedConstant()
class Output(Names):
ENGAGE_LOCK = NamedConstant()
DISENGAGE_LOCK = NamedConstant()
class State(Names):
LOCKED = NamedConstant()
UNLOCKED = NamedConstant()
ACTIVE = NamedConstant()
# end setup
# begin table def
from machinist import TransitionTable
table = TransitionTable()
# end table def
# begin first transition
table = table.addTransition(
State.LOCKED, Input.FARE_PAID, [Output.DISENGAGE_LOCK], State.ACTIVE)
# end first transition
# begin second transition
table = table.addTransition(
State.UNLOCKED, Input.ARM_TURNED, [Output.ENGAGE_LOCK], State.ACTIVE)
# end second transition
# begin last transitions
table = table.addTransitions(
State.ACTIVE, {
示例15: TurnstileInput
class TurnstileInput(Names):
FARE_PAID = NamedConstant()
ARM_UNLOCKED = NamedConstant()
ARM_TURNED = NamedConstant()
ARM_LOCKED = NamedConstant()
class TurnstileOutput(Names):
ENGAGE_LOCK = NamedConstant()
DISENGAGE_LOCK = NamedConstant()
class TurnstileState(Names):
LOCKED = NamedConstant()
UNLOCKED = NamedConstant()
ACTIVE = NamedConstant()
table = TransitionTable()
table = table.addTransitions(
TurnstileState.UNLOCKED, {
TurnstileInput.ARM_TURNED:
([TurnstileOutput.ENGAGE_LOCK], TurnstileState.ACTIVE),
})
table = table.addTransitions(
TurnstileState.ACTIVE, {
TurnstileInput.ARM_LOCKED: ([], TurnstileState.LOCKED),
TurnstileInput.ARM_UNLOCKED: ([], TurnstileState.UNLOCKED),
})
table = table.addTransitions(
TurnstileState.LOCKED, {
TurnstileInput.FARE_PAID:
([TurnstileOutput.DISENGAGE_LOCK], TurnstileState.ACTIVE),
})