def AdaptedWorkflow( workflow ):
    """
    wraps a IWorkflow utility into an adapter for use as an adapted workflow
    """

    assert IWorkflow.providedBy( workflow )
    
    class AdaptedWorkflow( AdaptedWorkflowBase ):

        def __init__( self, context):
            self.context = context
            self.workflow = workflow

            for m in IWorkflow.names():
                setattr( self, m, getattr( workflow, m ) ) 

    interface.classImplements( AdaptedWorkflow, IWorkflow )
    interface.directlyProvides( AdaptedWorkflow,
                                interface.directlyProvidedBy( AdaptedWorkflow ) + IAdaptedWorkflow )
    return AdaptedWorkflow
def ParallelWorkflow( workflow, wf_name, register_for=None):
    """
    wraps an IWorkflow and constructs IWorkflowState and IWorkflowInfo
    adapters, if register_for is specified registers them with the component
    architecture. else registration needs to be done by hand for the given
    name for all three.

    workflow is assumed to be a utility unless it implements IAdaptedWorkflow
    """

    assert IWorkflow.providedBy( workflow )
    
    class _ParallelWorkflowState( WorkflowState ):
        workflow_state_key = "%s.state"%(wf_name)
        workflow_id_key = "%s.id"%(wf_name)

    class _ParallelWorkflowInfo( ParallelWorkflowInfo ):
        name = wf_name
        
    if not register_for:
        return [ workflow, _ParallelWorkflowState, _ParallelWorkflowInfo ]

    # when you have a few these, zcml registration can be tedious, try to optionally
    # automate some of the pain, even if only for the global site manager
    
    if IAdaptedWorkflow.providedBy( workflow ):
        component.provideAdapter( workflow, (register_for,), IWorkflow, wf_name )
    else:
        component.provideUtility( workflow, IWorkflow, wf_name )

    component.provideAdapter( _ParallelWorkflowInfo,
                              (register_for, ),
                              IWorkflowInfo,
                              wf_name )
    
    component.provideAdapter( _ParallelWorkflowState,
                              (register_for, ),
                              IWorkflowState,
                              wf_name )

    return [ workflow, _ParallelWorkflowState, _ParallelWorkflowInfo ]
        def __init__( self, context):
            self.context = context
            self.workflow = workflow

            for m in IWorkflow.names():
                setattr( self, m, getattr( workflow, m ) )