[Zope3-checkins] CVS: Zope3/src/zope/app/workflow/stateful - xmlimportexport.py:1.13

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Apr 16 07:51:55 EDT 2004


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

Modified Files:
	xmlimportexport.py 
Log Message:


The sax API changed. Use parseString instead of parse now.



Fix up Export/Import Handlers/Adapters to not require a PD as argument for
export/import. It is the context of the adapter now.



Convert handlers to adapters.




=== Zope3/src/zope/app/workflow/stateful/xmlimportexport.py 1.12 => 1.13 ===
--- Zope3/src/zope/app/workflow/stateful/xmlimportexport.py:1.12	Mon Mar  8 07:06:25 2004
+++ Zope3/src/zope/app/workflow/stateful/xmlimportexport.py	Fri Apr 16 07:51:55 2004
@@ -15,7 +15,7 @@
 
 $Id$
 """
-from xml.sax import parse
+from xml.sax import parseString
 from xml.sax.handler import ContentHandler
 
 from zope.configuration.name import resolve
@@ -52,6 +52,7 @@
 
 
 class XMLStatefulImporter(ContentHandler):
+
     def __init__(self, context, encoding='latin-1'):
         self.context = context
         self.encoding = encoding
@@ -136,19 +137,22 @@
 
 class XMLImportHandler(object):
     implements(IProcessDefinitionImportHandler)
+    
+    def __init__(self, context):
+        self.context = context
 
-    # XXX Implementation needs more work !!
-    # check if xml-data can be imported and represents a StatefulPD
-    def canImport(self, context, data):
+    def canImport(self, data):
+        # XXX Implementation needs more work !!
+        # check if xml-data can be imported and represents a StatefulPD
         checker = XMLFormatChecker()
-        parse(data, checker)
-        return (bool(IStatefulProcessDefinition.providedBy(context)) 
+        parseString(data, checker)
+        return (bool(IStatefulProcessDefinition.providedBy(self.context)) 
                 and checker.isValid())
 
-    def doImport(self, context, data):
-        # XXX Manually clean ProcessDefinition ??
-        context.clear()
-        parse(data, XMLStatefulImporter(context))
+    def doImport(self, data):
+        # Clear the process definition
+        self.context.clear()
+        parseString(data, XMLStatefulImporter(self.context))
 
 
 class XMLExportHandler(object):
@@ -156,16 +160,15 @@
 
     template = ViewPageTemplateFile('xmlexport_template.pt')
 
-    def doExport(self, context, process_definition):
-        # XXX Not really nice to fake a BrowserView here ....
+    def __init__(self, context):
+        self.context = context    
+
+    def doExport(self):
+        # Unfortunately, the template expects its parent to have an attribute
+        # called request.
         self.request = None
-        self.process_definition = process_definition
-        self.context = context
         return self.template()
 
-    def getDefinition(self):
-        return self.process_definition
-
     def getDublinCore(self, obj):
         return IZopeDublinCore(obj)
 
@@ -180,7 +183,7 @@
 
     def getSchemaPermissions(self):
         info = []
-        perms = self.getDefinition().schemaPermissions
+        perms = self.context.schemaPermissions
         for field, (getPerm, setPerm) in perms.items():
             info.append({'fieldName': field,
                          'type': 'get',
@@ -191,7 +194,7 @@
         return info
 
     def relevantDataSchema(self):
-        schema = self.getDefinition().relevantDataSchema
+        schema = self.context.relevantDataSchema
         if schema is None:
             return 'None'
         return schema.__module__ + '.' + schema.getName()




More information about the Zope3-Checkins mailing list