[CMF-checkins] CVS: CMF/CMFSetup - utils.py:1.8 workflow.py:1.8

Tres Seaver tseaver at zope.com
Tue Jun 8 19:56:05 EDT 2004


Update of /cvs-repository/CMF/CMFSetup
In directory cvs.zope.org:/tmp/cvs-serv16733

Modified Files:
	utils.py workflow.py 
Log Message:


  - utils.py:

    o Move generic DOM parsing utilities here from workflow.py.

  - workflow.py:

    o Remove crufty SAX-based parser for Workflow Definitions.


=== CMF/CMFSetup/utils.py 1.7 => 1.8 ===
--- CMF/CMFSetup/utils.py:1.7	Tue May 25 18:35:51 2004
+++ CMF/CMFSetup/utils.py	Tue Jun  8 19:56:03 2004
@@ -107,3 +107,47 @@
 
         return content.encode( self._encoding )
 
+#
+#   DOM parsing utilities
+#
+def _getNodeAttribute( node, attr_name, encoding=None ):
+
+    """ Extract a string-valued attribute from node.
+    """
+    value = node.attributes[ attr_name ].nodeValue
+
+    if encoding is not None:
+        value = value.encode( encoding )
+
+    return value
+
+def _getNodeAttributeBoolean( node, attr_name ):
+
+    """ Extract a string-valued attribute from node.
+    """
+    value = node.attributes[ attr_name ].nodeValue.lower()
+
+    return value in ( 'true', 'yes', '1' )
+
+def _coalesceTextNodeChildren( node, encoding=None ):
+
+    """ Concatenate all childe text nodes into a single string.
+    """
+    from xml.dom import Node
+    fragments = []
+    node.normalize()
+    child = node.firstChild
+
+    while child is not None:
+
+        if child.nodeType == Node.TEXT_NODE:
+            fragments.append( child.nodeValue )
+
+        child = child.nextSibling
+
+    joined = ''.join( fragments )
+
+    if encoding is not None:
+        joined = joined.encode( encoding )
+
+    return joined


=== CMF/CMFSetup/workflow.py 1.7 => 1.8 ===
--- CMF/CMFSetup/workflow.py:1.7	Tue Jun  8 19:51:45 2004
+++ CMF/CMFSetup/workflow.py	Tue Jun  8 19:56:03 2004
@@ -16,6 +16,9 @@
 from permissions import ManagePortal
 from utils import HandlerBase
 from utils import _xmldir
+from utils import _getNodeAttribute
+from utils import _getNodeAttributeBoolean
+from utils import _coalesceTextNodeChildren
 
 TRIGGER_TYPES = ( 'AUTOMATIC', 'USER', 'WORKFLOW_METHOD' )
 
@@ -240,21 +243,6 @@
                , scripts
                )
 
-        parser = _WorkflowDefinitionParser( encoding )
-        parseString( xml, parser )
-
-        return ( parser._workflow_id
-               , parser._title
-               , parser._state_variable
-               , parser._initial_state
-               , parser._states
-               , parser._transitions
-               , parser._variables
-               , parser._worklists
-               , parser._permissions
-               , parser._scripts
-               )
-
     #
     #   Helper methods
     #
@@ -678,136 +666,12 @@
 
 InitializeClass( _WorkflowToolParser )
 
-class _WorkflowDefinitionParser( HandlerBase ):
-
-    security = ClassSecurityInfo()
-
-    def __init__( self, encoding ):
-
-        self._encoding = encoding
-        self._workflow_id = None
-        self._title = None
-        self._state_variable = None
-        self._initial_state = None
-        self._states = []
-        self._transitions = []
-        self._variables = []
-        self._worklists = []
-        self._permissions = []
-        self._scripts = []
-        self._current = None
-        self._permission_map = None
-        self._permission_role = None
-
-    security.declarePrivate( 'startElement' )
-    def startElement( self, name, attrs ):
-
-        if name == 'dc-workflow':
-
-            self._workflow_id = self._extract( attrs, 'workflow_id' )
-            self._title = self._extract( attrs, 'title' )
-            self._state_variable = self._extract( attrs, 'state_variable' )
-            self._initial_state = self._extract( attrs, 'initial_state' )
-
-        elif name == 'state':
-
-            info = { 'state_id' : self._extract( attrs, 'state_id' )
-                   , 'title' : self._extract( attrs, 'title' )
-                   , 'description' : []
-                   }
-
-            self._states.append( info )
-            self._current = info
-
-        elif name == 'permission-map':
-
-            info = { 'name' : self._extract( attrs, 'name' )
-                   , 'acquired' : self._extractBoolean( attrs
-                                                      , 'acquired', True )
-                   , 'roles' : []
-                   }
-
-            self._current.setdefault( 'permission_map', [] ).append( info )
-            self._permission_map = info
-
-        elif name == 'permission-role':
-
-            self._permission_role = []
-
-    security.declarePrivate( 'endElement' )
-    def endElement( self, name ):
-
-        if name == 'permission-role':
-            self._permission_map[ 'roles' ].append(
-                                            ''.join( self._permission_role ) )
-            self._permission_role = None
-
-        elif self._current is not None:
-            desc = ''.join( self._current[ 'description' ] )
-            self._current[ 'description' ] = desc
-
-        self._current = None
-        self._permission_map = None
-
-    security.declarePrivate( 'characters' )
-    def characters( self, text ):
-
-        if self._permission_role is not None:
-            self._permission_role.append( text )
-        elif self._current is not None and 'description' in self._current:
-            self._current[ 'description' ].append( text )
-                   
-
-InitializeClass( _WorkflowDefinitionParser )
 
 def _getWorkflowFilename( workflow_id ):
 
     """ Return the name of the file which holds info for a given type.
     """
     return 'workflows/%s/definition.xml' % workflow_id.replace( ' ', '_' )
-
-
-def _getNodeAttribute( node, attr_name, encoding=None ):
-
-    """ Extract a string-valued attribute from node.
-    """
-    value = node.attributes[ attr_name ].nodeValue
-
-    if encoding is not None:
-        value = value.encode( encoding )
-
-    return value
-
-def _getNodeAttributeBoolean( node, attr_name ):
-
-    """ Extract a string-valued attribute from node.
-    """
-    value = node.attributes[ attr_name ].nodeValue.lower()
-
-    return value in ( 'true', 'yes', '1' )
-
-def _coalesceTextNodeChildren( node, encoding=None ):
-
-    """ Concatenate all childe text nodes into a single string.
-    """
-    from xml.dom import Node
-    fragments = []
-    node.normalize()
-    child = node.firstChild
-
-    while child is not None:
-
-        if child.nodeType == Node.TEXT_NODE:
-            fragments.append( child.nodeValue )
-
-        child = child.nextSibling
-
-    joined = ''.join( fragments )
-
-    if encoding is not None:
-        joined = joined.encode( encoding )
-
-    return joined
 
 def _extractStateNodes( root, encoding=None ):
 




More information about the CMF-checkins mailing list