def upon(self, input, enter, outputs, collector=list): """ Declare a state transition within the :class:`automat.MethodicalMachine` associated with this :class:`automat.MethodicalState`: upon the receipt of the `input`, enter the `state`, emitting each output in `outputs`. :param MethodicalInput input: The input triggering a state transition. :param MethodicalState enter: The resulting state. :param Iterable[MethodicalOutput] outputs: The outputs to be triggered as a result of the declared state transition. :param Callable collector: The function to be used when collecting output return values. :raises TypeError: if any of the `outputs` signatures do not match the `inputs` signature. :raises ValueError: if the state transition from `self` via `input` has already been defined. """ inputSpec = getArgsSpec(input.method) for output in outputs: outputSpec = getArgsSpec(output.method) if inputSpec != outputSpec: raise TypeError( "method {input} signature {inputSignature} " "does not match output {output} " "signature {outputSignature}".format( input=input.method.__name__, output=output.method.__name__, inputSignature=inputSpec, outputSignature=outputSpec, )) self.machine._oneTransition(self, input, enter, outputs, collector)
def upon(self, input, enter, outputs, collector=list): """ Declare a state transition within the :class:`automat.MethodicalMachine` associated with this :class:`automat.MethodicalState`: upon the receipt of the `input`, enter the `state`, emitting each output in `outputs`. :param MethodicalInput input: The input triggering a state transition. :param MethodicalState enter: The resulting state. :param Iterable[MethodicalOutput] outputs: The outputs to be triggered as a result of the declared state transition. :param Callable collector: The function to be used when collecting output return values. :raises TypeError: if any of the `outputs` signatures do not match the `inputs` signature. :raises ValueError: if the state transition from `self` via `input` has already been defined. """ inputArgs = _getArgNames(input.argSpec) for output in outputs: outputArgs = _getArgNames(output.argSpec) if not outputArgs.issubset(inputArgs): raise TypeError( "method {input} signature {inputSignature} " "does not match output {output} " "signature {outputSignature}".format( input=input.method.__name__, output=output.method.__name__, inputSignature=getArgsSpec(input.method), outputSignature=getArgsSpec(output.method), )) self.machine._oneTransition(self, input, enter, outputs, collector)
def upon(self, input, enter, outputs, collector=list): """ Declare a state transition within the L{MethodicalMachine} associated with this L{MethodicalState}: upon the receipt of the input C{input}, enter the state C{enter}, emitting each output in C{outputs}. """ inputSpec = getArgsSpec(input.method) for output in outputs: outputSpec = getArgsSpec(output.method) if inputSpec != outputSpec: raise TypeError( "method {input} signature {inputSignature} " "does not match output {output} " "signature {outputSignature}".format( input=input.method.__name__, output=output.method.__name__, inputSignature=inputSpec, outputSignature=outputSpec, )) self.machine._oneTransition(self, input, enter, outputs, collector)
def _getArgSpec(func): """ Normalize inspect.ArgSpec across python versions and convert mutable attributes to immutable types. :param Callable func: A function. :return: The function's ArgSpec. :rtype: ArgSpec """ spec = getArgsSpec(func) return ArgSpec( args=tuple(spec.args), varargs=spec.varargs, varkw=spec.varkw if six.PY3 else spec.keywords, defaults=spec.defaults if spec.defaults else (), kwonlyargs=tuple(spec.kwonlyargs) if six.PY3 else (), kwonlydefaults=( tuple(spec.kwonlydefaults.items()) if spec.kwonlydefaults else ()) if six.PY3 else (), annotations=tuple(spec.annotations.items()) if six.PY3 else (), )
def _getArgSpec(func): """ Normalize inspect.ArgSpec across python versions and convert mutable attributes to immutable types. :param Callable func: A function. :return: The function's ArgSpec. :rtype: ArgSpec """ spec = getArgsSpec(func) return ArgSpec( args=tuple(spec.args), varargs=spec.varargs, varkw=spec.varkw if six.PY3 else spec.keywords, defaults=spec.defaults if spec.defaults else (), kwonlyargs=tuple(spec.kwonlyargs) if six.PY3 else (), kwonlydefaults=( tuple(spec.kwonlydefaults.items()) if spec.kwonlydefaults else () ) if six.PY3 else (), annotations=tuple(spec.annotations.items()) if six.PY3 else (), )