Skip to content

Commit

Permalink
move specs.Assign to operators.
Browse files Browse the repository at this point in the history
  • Loading branch information
knipknap committed Apr 10, 2012
1 parent 854d4d9 commit f6b71f4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 59 deletions.
42 changes: 42 additions & 0 deletions SpiffWorkflow/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,48 @@ def deserialize(cls, serializer, s_state):
"""
return serializer._deserialize_attrib(self, s_state)

class Assign(object):
"""
Assigns a new value to an attribute. The source may be either
a static value, or another attribute.
"""

def __init__(self,
left_attribute,
right_attribute = None,
right = None,
**kwargs):
"""
Constructor.
@type left_attribute: str
@param left_attribute: The name of the attribute to which the value
is assigned.
@type right: object
@param right: A static value that, when given, is assigned to
left_attribute.
@type right_attribute: str
@param right_attribute: When given, the attribute with the given
name is used as the source (instead of the
static value).
@type kwargs: dict
@param kwargs: See L{SpiffWorkflow.specs.TaskSpec}.
"""
if not right_attribute and not right:
raise ValueError('require argument: right_attribute or right')
assert left_attribute is not None
self.left_attribute = left_attribute
self.right_attribute = right_attribute
self.right = right

def assign(self, from_obj, to_obj):
# Fetch the value of the right expression.
if self.right is not None:
right = self.right
else:
right = from_obj.get_attribute(self.right_attribute)
to_obj.set_attribute(**{str(self.left_attribute): right})

def valueof(scope, op):
if op is None:
return None
Expand Down
57 changes: 0 additions & 57 deletions SpiffWorkflow/specs/Assign.py

This file was deleted.

1 change: 0 additions & 1 deletion SpiffWorkflow/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from Simple import Simple
from StartTask import StartTask
from SubWorkflow import SubWorkflow
from Assign import Assign
from ThreadMerge import ThreadMerge
from ThreadSplit import ThreadSplit
from Trigger import Trigger
Expand Down
2 changes: 1 addition & 1 deletion SpiffWorkflow/storage/XmlSerializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _deserialize_assign(self, workflow, start_node):
kwargs['right'] = value
else:
kwargs['right_attribute'] = attrib
return specs.Assign(name, **kwargs)
return operators.Assign(name, **kwargs)

def _deserialize_property(self, workflow, start_node):
"""
Expand Down

0 comments on commit f6b71f4

Please sign in to comment.