+
+ Execute a new command and add it to the stack.
+
+ >>> cm = CommandMessage('CommandC', {'param':'E'})
+ >>> c.execute_command(hooke=None, command_message=cm)
+ EXECUTE CommandC {'param': 'E'}
+ >>> c.append(cm)
+ >>> print [repr(cm) for cm in c] # doctest: +NORMALIZE_WHITESPACE
+ ['<CommandMessage CommandA {param: A}>',
+ '<CommandMessage CommandB {param: B}>',
+ '<CommandMessage CommandA {param: C}>',
+ '<CommandMessage CommandB {param: D}>',
+ '<CommandMessage CommandC {param: E}>']
+
+ The data-type is also pickleable, which ensures we can move it
+ between processes with :class:`multiprocessing.Queue`\s and easily
+ save it to disk. We must remove the unpickleable dummy executor
+ before testing though.
+
+ >>> c.execute_command # doctest: +ELLIPSIS
+ <function execute_cmd at 0x...>
+ >>> del(c.__dict__['execute_command'])
+ >>> c.execute_command # doctest: +ELLIPSIS
+ <bound method CommandStack.execute_command of ...>
+
+ Lets also attach a child command message to demonstrate recursive
+ serialization (we can't append `c` itself because of
+ `Python issue 1062277`_).
+
+ .. _Python issue 1062277: http://bugs.python.org/issue1062277
+
+ >>> import copy
+ >>> c.append(CommandMessage('CommandD', {'param': copy.deepcopy(c)}))
+
+ Run the pickle (and YAML) tests.
+
+ >>> import pickle
+ >>> s = pickle.dumps(c)
+ >>> z = pickle.loads(s)
+ >>> print '\\n'.join([repr(cm) for cm in c]
+ ... ) # doctest: +NORMALIZE_WHITESPACE,
+ <CommandMessage CommandA {param: A}>
+ <CommandMessage CommandB {param: B}>
+ <CommandMessage CommandA {param: C}>
+ <CommandMessage CommandB {param: D}>
+ <CommandMessage CommandC {param: E}>
+ <CommandMessage CommandD {param:
+ [<CommandMessage CommandA {param: A}>,
+ <CommandMessage CommandB {param: B}>,
+ <CommandMessage CommandA {param: C}>,
+ <CommandMessage CommandB {param: D}>,
+ <CommandMessage CommandC {param: E}>]}>
+ >>> import yaml
+ >>> print yaml.dump(c) # doctest: +REPORT_UDIFF
+ !!python/object/new:hooke.command_stack.CommandStack
+ listitems:
+ - !!python/object:hooke.engine.CommandMessage
+ arguments: {param: A}
+ command: CommandA
+ explicit_user_call: true
+ - !!python/object:hooke.engine.CommandMessage
+ arguments: {param: B}
+ command: CommandB
+ explicit_user_call: true
+ - !!python/object:hooke.engine.CommandMessage
+ arguments: {param: C}
+ command: CommandA
+ explicit_user_call: true
+ - !!python/object:hooke.engine.CommandMessage
+ arguments: {param: D}
+ command: CommandB
+ explicit_user_call: true
+ - !!python/object:hooke.engine.CommandMessage
+ arguments: {param: E}
+ command: CommandC
+ explicit_user_call: true
+ - !!python/object:hooke.engine.CommandMessage
+ arguments:
+ param: !!python/object/new:hooke.command_stack.CommandStack
+ listitems:
+ - !!python/object:hooke.engine.CommandMessage
+ arguments: {param: A}
+ command: CommandA
+ explicit_user_call: true
+ - !!python/object:hooke.engine.CommandMessage
+ arguments: {param: B}
+ command: CommandB
+ explicit_user_call: true
+ - !!python/object:hooke.engine.CommandMessage
+ arguments: {param: C}
+ command: CommandA
+ explicit_user_call: true
+ - !!python/object:hooke.engine.CommandMessage
+ arguments: {param: D}
+ command: CommandB
+ explicit_user_call: true
+ - !!python/object:hooke.engine.CommandMessage
+ arguments: {param: E}
+ command: CommandC
+ explicit_user_call: true
+ command: CommandD
+ explicit_user_call: true
+ <BLANKLINE>
+
+ There is also a convenience function for clearing the stack.
+
+ >>> c.clear()
+ >>> print [repr(cm) for cm in c]
+ []
+
+ YAMLize a curve argument.
+
+ >>> from .curve import Curve
+ >>> c.append(CommandMessage('curve info', {'curve': Curve(path=None)}))
+ >>> print yaml.dump(c) # doctest: +REPORT_UDIFF
+ !!python/object/new:hooke.command_stack.CommandStack
+ listitems:
+ - !!python/object:hooke.engine.CommandMessage
+ arguments:
+ curve: !!python/object:hooke.curve.Curve {}
+ command: curve info
+ explicit_user_call: true
+ <BLANKLINE>