-# Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2012 W. Trevor King <wking@tremily.us>
#
# This file is part of Hooke.
#
-# Hooke is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
#
-# Hooke is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
-# Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
#
-# You should have received a copy of the GNU Lesser General Public
-# License along with Hooke. If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with Hooke. If not, see <http://www.gnu.org/licenses/>.
"""The ``command_stack`` module provides tools for managing and
executing stacks of :class:`~hooke.engine.CommandMessage`\s.
>>> def execute_cmd(hooke, command_message, stack=None):
... cm = command_message
- ... print 'EXECUTE', cm.command, cm.arguments
+ ... print('EXECUTE {} {}'.format(cm.command, cm.arguments))
>>> c.execute_command = execute_cmd
>>> c.execute(hooke=None) # doctest: +ELLIPSIS
>>> 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
+ >>> print([repr(cm) for cm in c]) # doctest: +NORMALIZE_WHITESPACE
['<CommandMessage CommandA {param: A}>',
'<CommandMessage CommandB {param: B}>',
'<CommandMessage CommandA {param: C}>',
>>> import pickle
>>> s = pickle.dumps(c)
>>> z = pickle.loads(s)
- >>> print '\\n'.join([repr(cm) for cm in c]
- ... ) # doctest: +NORMALIZE_WHITESPACE,
+ >>> 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}>]}>
>>> import yaml
- >>> print yaml.dump(c) # doctest: +REPORT_UDIFF
+ >>> print(yaml.dump(c)) # doctest: +REPORT_UDIFF
!!python/object/new:hooke.command_stack.CommandStack
listitems:
- !!python/object:hooke.engine.CommandMessage
There is also a convenience function for clearing the stack.
>>> c.clear()
- >>> print [repr(cm) for cm in c]
+ >>> 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
+ >>> print(yaml.dump(c)) # doctest: +REPORT_UDIFF
!!python/object/new:hooke.command_stack.CommandStack
listitems:
- !!python/object:hooke.engine.CommandMessage
>>> c.append(CommandMessage('CommandB', {'param':'B'}))
>>> c.append(CommandMessage('CommandA', {'param':'C'}))
>>> c.append(CommandMessage('CommandB', {'param':'D'}))
- >>> print c.flatten()
+ >>> print(c.flatten())
- arguments: {param: A}
command: CommandA
- arguments: {param: B}
... '''
>>> c = FileCommandStack()
>>> c.from_string(string)
- >>> print [repr(cm) for cm in c] # doctest: +NORMALIZE_WHITESPACE
+ >>> print([repr(cm) for cm in c]) # doctest: +NORMALIZE_WHITESPACE
['<CommandMessage CommandA {param: A}>',
'<CommandMessage CommandB {param: B}>',
'<CommandMessage CommandA {param: C}>',