[Zope3-checkins] SVN: Zope3/trunk/src/zope/ Fixed some fssync bugs. Replaced direct streaming with temp file buffers and added a trusted adapter for attribute annotations.

Uwe Oestermeier uwe_oestermeier at iwm-kmrc.de
Wed Jan 24 05:13:58 EST 2007


Log message for revision 72206:
  Fixed some fssync bugs. Replaced direct streaming with temp file buffers and added a trusted adapter for attribute annotations.

Changed:
  U   Zope3/trunk/src/zope/app/fssync/browser/__init__.py
  U   Zope3/trunk/src/zope/app/fssync/configure.zcml
  U   Zope3/trunk/src/zope/app/fssync/interfaces.py
  U   Zope3/trunk/src/zope/app/fssync/syncer.py
  U   Zope3/trunk/src/zope/dublincore/fssync/adapter.py
  U   Zope3/trunk/src/zope/dublincore/fssync/configure.zcml
  U   Zope3/trunk/src/zope/fssync/fssync.py
  U   Zope3/trunk/src/zope/fssync/server/entryadapter.py

-=-
Modified: Zope3/trunk/src/zope/app/fssync/browser/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/fssync/browser/__init__.py	2007-01-24 10:08:19 UTC (rev 72205)
+++ Zope3/trunk/src/zope/app/fssync/browser/__init__.py	2007-01-24 10:13:57 UTC (rev 72206)
@@ -36,9 +36,11 @@
     """Helper to snarf a directory to the response."""
     response.setStatus(200)
     response.setHeader("Content-Type", "application/x-snarf")
-    snf = Snarfer(response)
+    
+    temp = tempfile.TemporaryFile('wb')
+    snf = Snarfer(temp)
     snf.addtree(dirname)
-    return ""
+    return temp
 
 class SnarfFile(BrowserView):
     """View returning a snarfed representation of an object tree.
@@ -126,7 +128,7 @@
             shutil.rmtree(self.tempdir)
 
     def unsnarf_body(self):
-        stream = self.request.bodyStream
+        stream = self.request.bodyStream.getCacheStream()
         uns = Unsnarfer(stream)
         uns.unsnarf(self.tempdir)
 

Modified: Zope3/trunk/src/zope/app/fssync/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/fssync/configure.zcml	2007-01-24 10:08:19 UTC (rev 72205)
+++ Zope3/trunk/src/zope/app/fssync/configure.zcml	2007-01-24 10:13:57 UTC (rev 72206)
@@ -2,7 +2,23 @@
     xmlns="http://namespaces.zope.org/zope"
     xmlns:fssync="http://namespaces.zope.org/fssync"
     >
-
+    
+  <adapter
+      for="zope.annotation.interfaces.IAttributeAnnotatable"
+      provides="zope.app.fssync.interfaces.IFSSyncAnnotations"
+      factory="zope.app.fssync.syncer.FSSyncAnnotations"
+      trusted="true"
+      />
+ 
+  <class class="zope.app.fssync.syncer.FSSyncAnnotations">
+    
+     <require
+         permission="zope.ManageContent"
+         interface="zope.app.fssync.interfaces.IFSSyncAnnotations" 
+         />
+  
+  </class>
+      
   <utility
       provides="zope.app.fssync.interfaces.IGlobalFSSyncUtility"
       component="zope.app.fssync.fsregistry.fsRegistry"
@@ -12,6 +28,7 @@
       factory="zope.fssync.server.entryadapter.DefaultFileAdpater"
       />
 
+  
 
   <!-- Include browser package -->
 

Modified: Zope3/trunk/src/zope/app/fssync/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/fssync/interfaces.py	2007-01-24 10:08:19 UTC (rev 72205)
+++ Zope3/trunk/src/zope/app/fssync/interfaces.py	2007-01-24 10:13:57 UTC (rev 72206)
@@ -18,7 +18,14 @@
 __docformat__ = 'restructuredtext'
 
 from zope.interface import Interface
+from zope.annotation.interfaces import IAnnotations
 
+class IFSSyncAnnotations(IAnnotations):
+    """Access to synchronizable annotations."""
+    
+    def __iter__():
+        """Iterates over the package-unique keys."""
+
 class IFactoryNotFoundError(Interface):
     pass
 

Modified: Zope3/trunk/src/zope/app/fssync/syncer.py
===================================================================
--- Zope3/trunk/src/zope/app/fssync/syncer.py	2007-01-24 10:08:19 UTC (rev 72205)
+++ Zope3/trunk/src/zope/app/fssync/syncer.py	2007-01-24 10:13:57 UTC (rev 72206)
@@ -18,20 +18,31 @@
 __docformat__ = 'restructuredtext'
 
 from zope.app import zapi
+from zope.interface import implements
 from zope.traversing.api import getPath
 from zope.annotation.interfaces import IAnnotations
+from zope.annotation.attribute import AttributeAnnotations
 from zope.fssync.server.syncer import Syncer
 from zope.app.fssync.interfaces import IGlobalFSSyncUtility
 
+from interfaces import IFSSyncAnnotations
+
+class FSSyncAnnotations(AttributeAnnotations):
+    """Default adapter for access to attribute annotations.
+       Should be registered as trusted adapter.
+    """
+    implements(IFSSyncAnnotations)
+
+
 def getObjectId(obj):
-    return str(getPath(obj))
+    return getPath(obj)
 
 def getSerializer(obj):
     syncUtility = zapi.getUtility(IGlobalFSSyncUtility)
     return syncUtility.getSynchronizer(obj)
 
 def getAnnotations(obj):
-    return IAnnotations(obj, None)
+    return IFSSyncAnnotations(obj, None)
 
 
 def toFS(obj, name, location):

Modified: Zope3/trunk/src/zope/dublincore/fssync/adapter.py
===================================================================
--- Zope3/trunk/src/zope/dublincore/fssync/adapter.py	2007-01-24 10:08:19 UTC (rev 72205)
+++ Zope3/trunk/src/zope/dublincore/fssync/adapter.py	2007-01-24 10:13:57 UTC (rev 72206)
@@ -21,6 +21,8 @@
 from zope.fssync.server.entryadapter import ObjectEntryAdapter
 from zope.fssync.server.interfaces import IObjectFile
 
+from zope.xmlpickle import dumps
+
 class ZDCAnnotationDataAdapter(ObjectEntryAdapter):
 
     implements(IObjectFile)

Modified: Zope3/trunk/src/zope/dublincore/fssync/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/dublincore/fssync/configure.zcml	2007-01-24 10:08:19 UTC (rev 72205)
+++ Zope3/trunk/src/zope/dublincore/fssync/configure.zcml	2007-01-24 10:13:57 UTC (rev 72206)
@@ -2,9 +2,18 @@
    xmlns="http://namespaces.zope.org/zope"
    xmlns:fssync="http://namespaces.zope.org/fssync">
 
+  <!-- Do we need the fssync:adapter statement at all? 
   <fssync:adapter
       class="zope.dublincore.annotatableadapter.ZDCAnnotationData"
       factory=".adapter.ZDCAnnotationDataAdapter"
       />
-
+   -->
+   
+   <adapter
+      for="zope.dublincore.annotatableadapter.ZDCAnnotationData"
+      factory=".adapter.ZDCAnnotationDataAdapter"
+      trusted="true"
+      permission="zope.ManageContent"
+      />
+   
 </configure>

Modified: Zope3/trunk/src/zope/fssync/fssync.py
===================================================================
--- Zope3/trunk/src/zope/fssync/fssync.py	2007-01-24 10:08:19 UTC (rev 72205)
+++ Zope3/trunk/src/zope/fssync/fssync.py	2007-01-24 10:13:57 UTC (rev 72206)
@@ -218,7 +218,16 @@
         else:
             conn.putrequest("POST", path)
             conn.putheader("Content-type", content_type)
-            conn.putheader("Transfer-encoding", "chunked")
+            #conn.putheader("Transfer-encoding", "chunked")
+            #XXX Chunking works only with the zserver. Twisted responds with
+            #    HTTP error 400 (Bad Request); error document:
+            #      Excess 4 bytes sent in chunk transfer mode
+            #We use a buffer as workaround and compute the Content-Length in
+            #advance
+            tmp = tempfile.TemporaryFile('w+b')
+            datasource(tmp)
+            conn.putheader("Content-Length", str(tmp.tell()))
+            
         if self.user_passwd:
             if ":" not in self.user_passwd:
                 auth = self.getToken(self.roottype,
@@ -231,8 +240,16 @@
         conn.putheader("Connection", "close")
         conn.endheaders()
         if datasource is not None:
-            datasource(PretendStream(conn))
-            conn.send("0\r\n\r\n")
+            #XXX If chunking works again, replace the following lines with 
+            # datasource(PretendStream(conn))
+            # conn.send("0\r\n\r\n")
+            tmp.seek(0)
+            data = tmp.read(1<<16)
+            while data:
+                conn.send(data)
+                data = tmp.read(1<<16)
+            tmp.close()   
+                
         response = conn.getresponse()
         if response.status != 200:
             raise Error("HTTP error %s (%s); error document:\n%s",
@@ -253,7 +270,7 @@
         # Too often, we just get HTTP response code 200 (OK), with an
         # HTML document that explains what went wrong.
         data = fp.read()
-        ctype = headers["Content-type"]
+        ctype = headers.get("Content-type", 'unknown')
         if ctype == "text/html":
             s = StringIO()
             f = formatter.AbstractFormatter(formatter.DumbWriter(s))

Modified: Zope3/trunk/src/zope/fssync/server/entryadapter.py
===================================================================
--- Zope3/trunk/src/zope/fssync/server/entryadapter.py	2007-01-24 10:08:19 UTC (rev 72205)
+++ Zope3/trunk/src/zope/fssync/server/entryadapter.py	2007-01-24 10:13:57 UTC (rev 72206)
@@ -18,12 +18,12 @@
 
 from zope.fssync.server.interfaces import IObjectFile, IContentDirectory
 from zope.interface import implements
-from zope.xmlpickle import toxml
+from zope.xmlpickle import dumps #toxml
 
 # TODO: This is a bug; we shouldn't depend on these packages at all.
 # Need to restructure.
 from zope.proxy import removeAllProxies
-from zope.app.fssync import fspickle
+#from zope.app.fssync import fspickle
 
 class AttrMapping(object):
     """Convenience object implementing a mapping on selected object attributes
@@ -93,8 +93,13 @@
 
     def getBody(self):
         "See IObjectFile"
-        s = fspickle.dumps(self.context)
-        return toxml(s)
+        
+        #uo: why was fspickle used here? To keep references to locatable objects?
+        #s = fspickle.dumps(self.context)
+        #return toxml(s)
+        
+        #If we use zope.xmlpickle.dumps we always get the xml elements in a fixed order
+        return dumps(self.context)
 
     def setBody(self, body):
         "See IObjectFile"



More information about the Zope3-Checkins mailing list