[Zope3-checkins] CVS: Zope3/src/zope/app/workflow/stateful - configure.zcml:1.1.4.1 contentworkflow.py:1.1.4.1 definition.py:1.1.4.1 instance.py:1.1.4.1 xmlimportexport.py:1.1.4.1

Grégoire Weber zope@i-con.ch
Sun, 22 Jun 2003 10:24:06 -0400


Update of /cvs-repository/Zope3/src/zope/app/workflow/stateful
In directory cvs.zope.org:/tmp/cvs-serv24874/src/zope/app/workflow/stateful

Modified Files:
      Tag: cw-mail-branch
	configure.zcml contentworkflow.py definition.py instance.py 
	xmlimportexport.py 
Log Message:
Synced up with HEAD

=== Zope3/src/zope/app/workflow/stateful/configure.zcml 1.1 => 1.1.4.1 ===
--- Zope3/src/zope/app/workflow/stateful/configure.zcml:1.1	Thu May  8 13:27:19 2003
+++ Zope3/src/zope/app/workflow/stateful/configure.zcml	Sun Jun 22 10:23:35 2003
@@ -11,8 +11,10 @@
       />
   <require
       permission="zope.workflow.ManageProcessDefinitions"
-      interface="zope.app.interfaces.workflow.stateful.IStatefulProcessDefinition"
-      set_schema="zope.app.interfaces.workflow.stateful.IStatefulProcessDefinition" 
+      interface="
+         zope.app.interfaces.workflow.stateful.IStatefulProcessDefinition"
+      set_schema="
+         zope.app.interfaces.workflow.stateful.IStatefulProcessDefinition" 
       />
   <require
       permission="zope.workflow.ManageProcessDefinitions"
@@ -22,7 +24,7 @@
       interface="zope.app.interfaces.annotation.IAttributeAnnotatable" 
       />
   <implements 
-      interface="zope.app.interfaces.services.configuration.IUseConfigurable" 
+      interface="zope.app.interfaces.services.registration.IRegisterable" 
       />
 </content>
 


=== Zope3/src/zope/app/workflow/stateful/contentworkflow.py 1.1 => 1.1.4.1 ===
--- Zope3/src/zope/app/workflow/stateful/contentworkflow.py:1.1	Thu May  8 13:27:19 2003
+++ Zope3/src/zope/app/workflow/stateful/contentworkflow.py	Sun Jun 22 10:23:35 2003
@@ -19,12 +19,9 @@
 """
 __metaclass__ = type
 
-from zope.interface import Interface
 from persistence import Persistent
 from zope.component import getService, queryAdapter
-from zope.component.exceptions import ComponentLookupError
-from zope.proxy.context import ContextMethod
-from zope.proxy.introspection import removeAllProxies
+from zope.context import ContextMethod
 
 from zope.app.interfaces.event import ISubscriber
 from zope.app.interfaces.event import IObjectCreatedEvent
@@ -33,12 +30,12 @@
 from zope.app.interfaces.workflow import IProcessInstanceContainer
 from zope.app.interfaces.workflow import IProcessInstanceContainerAdaptable
 from zope.app.interfaces.workflow.stateful import IContentWorkflowsUtility
-
+from zope.interface import implements
 
 
 class ContentWorkflowsUtility(Persistent):
 
-    __implements__ = IContentWorkflowsUtility, ISubscriber
+    implements(IContentWorkflowsUtility, ISubscriber)
 
     def __init__(self):
         super(ContentWorkflowsUtility, self).__init__()
@@ -51,18 +48,18 @@
         obj = event.object
 
         # XXX Do i need to removeAllProxies somewhere in here ???
-        
+
         # check if it implements IProcessInstanceContainerAdaptable
         if not IProcessInstanceContainerAdaptable.isImplementedBy(obj):
             return
-        
+
         pi_container = queryAdapter(obj, IProcessInstanceContainer)
         # probably need to adapt to IZopeContainer to use pi_container with
         # context.
         if pi_container is None:
             # Object can't have associated PIs.
             return
-        
+
         if IObjectCreatedEvent.isImplementedBy(event):
             wfs = getService(self, Workflows)
 
@@ -70,7 +67,7 @@
             # for the newly created compoent. For every pd_name
             # returned we will create a processinstance.
             for pd_name in self._names:
-                
+
                 if pd_name in pi_container.keys():
                     continue
                 try:
@@ -80,7 +77,7 @@
                     # No registered PD with that name..
                     continue
                 pi_container.setObject(pd_name, pi)
-                
+
     notify = ContextMethod(notify)
 
     # IContentWorkflowsUtility


=== Zope3/src/zope/app/workflow/stateful/definition.py 1.1 => 1.1.4.1 ===
--- Zope3/src/zope/app/workflow/stateful/definition.py:1.1	Thu May  8 13:27:19 2003
+++ Zope3/src/zope/app/workflow/stateful/definition.py	Sun Jun 22 10:23:35 2003
@@ -19,15 +19,13 @@
 __metaclass__ = type
 
 from persistence import Persistent
-from persistence.dict import PersistentDict
 
-from zope.proxy.context import ContextMethod, ContextWrapper
-from zope.proxy.context import getWrapperData, getWrapperContainer
-from zope.proxy.context import getWrapperContext
+from zope.app.context import ContextWrapper
+from zope.context import getWrapperContainer
+from zope.context import ContextMethod
 
 from zope.app.interfaces.container import IReadContainer
 
-from zope.app.interfaces.workflow import IProcessDefinition
 from zope.app.interfaces.workflow.stateful import IStatefulProcessDefinition
 from zope.app.interfaces.workflow.stateful import IState, ITransition
 from zope.app.interfaces.workflow.stateful import IStatefulStatesContainer
@@ -36,26 +34,26 @@
 from zope.app.workflow.definition import ProcessDefinition
 from zope.app.workflow.definition import ProcessDefinitionElementContainer
 from zope.app.workflow.stateful.instance import StatefulProcessInstance
-
+from zope.interface import implements
 
 
 class State(Persistent):
     """State."""
 
-    __implements__ = IState
+    implements(IState)
 
 
 
 class StatesContainer(ProcessDefinitionElementContainer):
     """Container that stores States.
     """
-    __implements__ = IStatefulStatesContainer
+    implements(IStatefulStatesContainer)
 
 
 class Transition(Persistent):
     """Transition."""
 
-    __implements__ = ITransition
+    implements(ITransition)
 
     def __init__(self, source=None, destination=None, condition=None,
                  script=None, permission=None, triggerMode=None):
@@ -127,19 +125,17 @@
         return getWrapperContainer(self).getProcessDefinition()
     getProcessDefinition = ContextMethod(getProcessDefinition)
 
-                    
 
 class TransitionsContainer(ProcessDefinitionElementContainer):
     """Container that stores Transitions.
     """
-    __implements__ = IStatefulTransitionsContainer
-
+    implements(IStatefulTransitionsContainer)
 
 
 class StatefulProcessDefinition(ProcessDefinition):
     """Stateful workflow process definition."""
 
-    __implements__ = IStatefulProcessDefinition, IReadContainer
+    implements(IStatefulProcessDefinition, IReadContainer)
 
     def __init__(self):
         super(StatefulProcessDefinition, self).__init__()
@@ -169,43 +165,43 @@
 
 
     states = property(lambda self: self.__states)
-    
+
     transitions = property(lambda self: self.__transitions)
-    
+
     def addState(self, name, state):
         if name in self.states:
             raise KeyError, name
         self.states.setObject(name, state)
-    
+
     def getState(self, name):
         return self.states[name]
     getState = ContextMethod(getState)
-    
+
     def removeState(self, name):
         del self.states[name]
-    
+
     def getStateNames(self):
         return self.states.keys()
 
     # XXX This shouldn't be hardcoded
     def getInitialStateName(self):
         return 'INITIAL'
-    
+
     def addTransition(self, name, transition):
         if name in self.transitions:
             raise KeyError, name
         self.transitions.setObject(name, transition)
-    
+
     def getTransition(self, name):
         return self.transitions[name]
     getTransition = ContextMethod(getTransition)
-    
+
     def removeTransition(self, name):
         del self.transitions[name]
-    
+
     def getTransitionNames(self):
         return self.transitions.keys()
-    
+
     # IProcessDefinition
 
     def createProcessInstance(self, definition_name):
@@ -224,52 +220,52 @@
 
     def __getitem__(self, key):
         "See Interface.Common.Mapping.IReadMapping"
- 
+
         result = self.get(key)
         if result is None:
             raise KeyError(key)
- 
+
         return result
-    
+
     __getitem__ = ContextMethod(__getitem__)
- 
+
     def get(self, key, default=None):
         "See Interface.Common.Mapping.IReadMapping"
- 
+
         if key == 'states':
             return self.states
- 
+
         if key == 'transitions':
             return self.transitions
 
         return default
- 
+
     get = ContextMethod(get)
- 
+
     def __contains__(self, key):
         "See Interface.Common.Mapping.IReadMapping"
- 
+
         return self.get(key) is not None
- 
+
     # Enumeration methods. We'll only expose Packages for now:
     def __iter__(self):
         return iter(self.keys())
- 
+
     def keys(self):
         return ['states', 'transitions']
- 
+
     def values(self):
         return map(self.get, self.keys())
- 
+
     values = ContextMethod(values)
- 
+
     def items(self):
         return [(key, self.get(key)) for key in self.keys()]
- 
+
     items = ContextMethod(items)
- 
+
     def __len__(self):
-        return 2    
+        return 2
 
 
     #


=== Zope3/src/zope/app/workflow/stateful/instance.py 1.1 => 1.1.4.1 ===
--- Zope3/src/zope/app/workflow/stateful/instance.py:1.1	Thu May  8 13:27:19 2003
+++ Zope3/src/zope/app/workflow/stateful/instance.py	Sun Jun 22 10:23:35 2003
@@ -20,16 +20,16 @@
 from types import StringTypes
 from persistence import Persistent
 from zope.schema import getFields
-from zope.interface import directlyProvides
+from zope.interface import directlyProvides, implements
 
 from zope.exceptions import Unauthorized
 
 from zope.component import getService
 from zope.component import getServiceManager
 
-from zope.proxy.introspection import removeAllProxies
-from zope.proxy.context import ContextMethod, getWrapperContainer
-from zope.proxy.context import ContextWrapper,ContextAware
+from zope.proxy import removeAllProxies
+from zope.context import ContextMethod
+from zope.app.context import ContextWrapper
 
 from zope.security.management import getSecurityManager
 from zope.security.checker import CheckerPublic
@@ -40,16 +40,13 @@
 #from zope.security.checker import Checker
 #from zope.security.proxy import getChecker, Proxy
 
-from zope.app.security.permission import checkPermission
-
 from zope.tales.engine import Engine
 
 from zope.app.interfaces.workflow.stateful import IStatefulProcessInstance
 from zope.app.workflow.instance import ProcessInstance
 
 
-
-class RelevantData(ContextAware):
+class RelevantData:
     pass
 
 # XXX Example of how Changes to Workflow Relevant Data would send out Events
@@ -98,17 +95,15 @@
     """Stateful Workflow ProcessInstance.
     """
 
-    __implements__ = IStatefulProcessInstance
+    implements(IStatefulProcessInstance)
 
 
     ############################################################
     # Implementation methods for interface
     # zope.app.interfaces.workflow.IStatefulProcessInstance
 
-
-
     data = property(lambda self: ContextWrapper(self._data, self))
-    
+
     # XXX this is not entirely tested nor finished
     #def _getData(self):
     #    """getter for Workflow Relevant Data."""
@@ -134,7 +129,6 @@
     #
     #data = property(lambda self: ContextWrapper(self._getData(), self))
 
-    
     def initialize(self):
         pd = self._getProcessDefinition()
         clean_pd = removeAllProxies(pd)
@@ -152,11 +146,10 @@
         else:
             self._data = None
         # setup permission on data
-        
+
         # check for Automatic Transitions
         self._checkAndFireAuto(clean_pd)
     initialize = ContextMethod(initialize)
-        
 
     def getOutgoingTransitions(self):
         pd = self._getProcessDefinition()
@@ -164,7 +157,6 @@
         return self._outgoingTransitions(clean_pd)
     getOutgoingTransitions = ContextMethod(getOutgoingTransitions)
 
-
     def fireTransition(self, id):
         pd = self._getProcessDefinition()
         clean_pd = removeAllProxies(pd)
@@ -177,7 +169,7 @@
         # send StatusChangingWorkflowEvent
         #print "send StatusChangingWorkflowEvent(old:%s, new:%s) here" \
         #      % (self._status, trans.destinationState)
-        
+
         # change status
         self._status = trans.destinationState
 
@@ -192,7 +184,7 @@
 
     #
     ############################################################
-    
+
     # XXX expose this method in the interface (without _) ???
     def _getProcessDefinition(self):
         """Get the ProcessDefinition object from WorkflowService.
@@ -201,8 +193,6 @@
         return svc.getProcessDefinition(self.processDefinitionName)
     _getProcessDefinition = ContextMethod(_getProcessDefinition)
 
-
-
     # XXX this is not entirely tested
     def _getContext(self):
         ctx = {}
@@ -214,7 +204,7 @@
         # how can we know if this ProcessInstance is annotated
         # to a Content-Object and provide secure ***READONLY***
         # Access to it for evaluating Transition Conditions ???
-        
+
         #content = getWrapperContainer(self)
 
         # XXX How can i make shure that nobody modifies content
@@ -231,9 +221,8 @@
         #    content = Proxy(content, checker)
 
         #ctx['content'] = content
-        
-        return ctx
 
+        return ctx
     _getContext = ContextMethod(_getContext)
 
 
@@ -241,7 +230,6 @@
         ctx['state_change'] = StateChangeInfo(transition)
         return ctx
 
-    
     def _evaluateCondition(self, transition, contexts):
         """Evaluate a condition in context of relevant-data.
         """
@@ -250,7 +238,6 @@
         expr = Engine.compile(transition.condition)
         return expr(Engine.getContext( contexts=contexts ))
 
-
     def _evaluateScript(self, transition, contexts):
         script = transition.script
         if not script:
@@ -261,7 +248,6 @@
         return script(contexts)
     _evaluateScript = ContextMethod(_evaluateScript)
 
-
     def _buildRelevantData(self, schema):
         """Create a new data object and initialize with Schema defaults.
         """
@@ -273,12 +259,11 @@
                 setattr(data, name, field.default)
         return data
 
-
     def _outgoingTransitions(self, clean_pd):
         sm = getSecurityManager()
         ret = []
         contexts = self._getContext()
-        
+
         for name, trans in clean_pd.transitions.items():
             if self.status == trans.sourceState:
                 # check permissions
@@ -299,7 +284,7 @@
                         include = 0
                     if not include:
                         continue
-                    
+
                 if trans.script is not None:
                     try:
                         include = self._evaluateScript(trans, ctx)
@@ -307,12 +292,11 @@
                         include = 0
                     if not include:
                         continue
-                    
+
                 # append transition name
                 ret.append(name)
         return ret
     _outgoingTransitions = ContextMethod(_outgoingTransitions)
-        
 
     def _checkAndFireAuto(self, clean_pd):
         outgoing_transitions = self.getOutgoingTransitions()
@@ -323,4 +307,3 @@
                 self.fireTransition(name)
                 return
     _checkAndFireAuto = ContextMethod(_checkAndFireAuto)
-


=== Zope3/src/zope/app/workflow/stateful/xmlimportexport.py 1.1 => 1.1.4.1 ===
--- Zope3/src/zope/app/workflow/stateful/xmlimportexport.py:1.1	Thu May  8 13:27:19 2003
+++ Zope3/src/zope/app/workflow/stateful/xmlimportexport.py	Sun Jun 22 10:23:35 2003
@@ -24,18 +24,16 @@
      import IStatefulProcessDefinition
 from zope.app.interfaces.workflow import IProcessDefinitionImportHandler
 from zope.app.interfaces.workflow import IProcessDefinitionExportHandler
-from zope.component import getAdapter, getServiceManager
+from zope.component import getAdapter
 from zope.app.interfaces.dublincore import IZopeDublinCore
-from types import StringTypes
-from zope.proxy.context import ContextMethod
-from zope.proxy.introspection import removeAllProxies
+from zope.proxy import removeAllProxies
 from zope.security.checker import CheckerPublic
 
 from xml.sax import parse
 from xml.sax.handler import ContentHandler
 
 from zope.app.workflow.stateful.definition import State, Transition
-
+from zope.interface import implements
 
 
 # basic implementation for a format-checker
@@ -51,18 +49,15 @@
     def endElement(self, name):
         pass
 
-
     def isValid(self):
         return self.__valid
 
 
-
-
 class XMLStatefulImporter(ContentHandler):
     def __init__(self, context, encoding='latin-1'):
         self.context = context
         self.encoding = encoding
-    
+
     def startElement(self, name, attrs):
         handler = getattr(self, 'start' + name.title().replace('-', ''), None)
         if not handler:
@@ -78,7 +73,7 @@
     def noop(*args):
         pass
 
-    startStates      = noop
+    startStates = noop
     startTransitions = noop
 
     def startWorkflow(self, attrs):
@@ -108,21 +103,22 @@
         permission = attrs.get('permission', '').encode(encoding)
         if permission == 'zope.Public':
             permission = CheckerPublic
-        trans = Transition(source = attrs['sourceState'].encode(encoding),
-                           destination = attrs['destinationState'].encode(encoding),
-                           condition = attrs.get('condition', '').encode(encoding),
-                           script = attrs.get('script', '').encode(encoding),
-                           permission = permission,
-                           triggerMode = attrs['triggerMode'].encode(encoding))
+        trans = Transition(
+                source = attrs['sourceState'].encode(encoding),
+                destination = attrs['destinationState'].encode(encoding),
+                condition = attrs.get('condition', '').encode(encoding),
+                script = attrs.get('script', '').encode(encoding),
+                permission = permission,
+                triggerMode = attrs['triggerMode'].encode(encoding)
+                )
         dc = getAdapter(trans, IZopeDublinCore)
         dc.title = attrs.get('title', u'')
         self.context.addTransition(name, trans)
 
 
-        
 class XMLImportHandler:
 
-    __implements__ = IProcessDefinitionImportHandler
+    implements(IProcessDefinitionImportHandler)
 
     # XXX Implementation needs more work !!
     # check if xml-data can be imported and represents a StatefulPD
@@ -131,17 +127,16 @@
         parse(data, checker)
         return bool(IStatefulProcessDefinition.isImplementedBy(context)) \
                and checker.isValid()
-    
 
     def doImport(self, context, data):
         # XXX Manually clean ProcessDefinition ??
         context.clear()
         parse(data, XMLStatefulImporter(context))
-    
+
 
 class XMLExportHandler:
 
-    __implements__ = IProcessDefinitionExportHandler
+    implements(IProcessDefinitionExportHandler)
 
     template = ViewPageTemplateFile('xmlexport_template.pt')