[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/ Removed the unnecessary and unused version argument from storeBlob.

Jim Fulton jim at zope.com
Fri May 18 14:02:15 EDT 2007


Log message for revision 75841:
  Removed the unnecessary and unused version argument from storeBlob.
  
  Added a temporaryDirectory method for getting a directory to use for
  creating temporary files.
  

Changed:
  U   ZODB/trunk/src/ZODB/Blobs/BlobStorage.py
  U   ZODB/trunk/src/ZODB/Blobs/interfaces.py
  U   ZODB/trunk/src/ZODB/Connection.py
  U   ZODB/trunk/src/ZODB/ExportImport.py

-=-
Modified: ZODB/trunk/src/ZODB/Blobs/BlobStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/Blobs/BlobStorage.py	2007-05-18 18:02:12 UTC (rev 75840)
+++ ZODB/trunk/src/ZODB/Blobs/BlobStorage.py	2007-05-18 18:02:14 UTC (rev 75841)
@@ -62,6 +62,11 @@
         self.__supportsUndo = supportsUndo
 
     @non_overridable
+    def temporaryDirectory(self):
+        return self.fshelper.base_dir
+
+
+    @non_overridable
     def __repr__(self):
         normal_storage = getProxiedObject(self)
         return '<BlobStorage proxy for %r at %s>' % (normal_storage,
@@ -114,13 +119,12 @@
                 os.unlink(clean) 
 
     @non_overridable
-    def loadBlob(self, oid, serial, version):
+    def loadBlob(self, oid, serial):
         """Return the filename where the blob file can be found.
-
         """
         filename = self.fshelper.getBlobFilename(oid, serial)
         if not os.path.exists(filename):
-            raise POSKeyError, "Not an existing blob."
+            return None
         return filename
 
     @non_overridable

Modified: ZODB/trunk/src/ZODB/Blobs/interfaces.py
===================================================================
--- ZODB/trunk/src/ZODB/Blobs/interfaces.py	2007-05-18 18:02:12 UTC (rev 75840)
+++ ZODB/trunk/src/ZODB/Blobs/interfaces.py	2007-05-18 18:02:14 UTC (rev 75841)
@@ -60,11 +60,16 @@
     def storeBlob(oid, oldserial, data, blob, version, transaction):
         """Stores data that has a BLOB attached."""
 
-    def loadBlob(oid, serial, version):
-        """Return the filename of the Blob data responding to this OID and
-        serial.
+    def loadBlob(oid, serial):
+        """Return the filename of the Blob data for this OID and serial.
 
         Returns a filename or None if no Blob data is connected with this OID. 
 
         Raises POSKeyError if the blobfile cannot be found.
         """
+
+    def temporaryDirectory():
+        """Return a directory that should be used for uncommitted blob data.
+
+        If Blobs use this, then commits can be performed with a simple rename.
+        """

Modified: ZODB/trunk/src/ZODB/Connection.py
===================================================================
--- ZODB/trunk/src/ZODB/Connection.py	2007-05-18 18:02:12 UTC (rev 75840)
+++ ZODB/trunk/src/ZODB/Connection.py	2007-05-18 18:02:14 UTC (rev 75841)
@@ -853,8 +853,7 @@
         providedBy = getattr(obj, '__providedBy__', None)
         if providedBy is not None and IBlob in providedBy:
             obj._p_blob_uncommitted = None
-            obj._p_blob_data = self._storage.loadBlob(
-                obj._p_oid, serial, self._version)
+            obj._p_blob_data = self._storage.loadBlob(obj._p_oid, serial)
 
     def _load_before_or_conflict(self, obj):
         """Load non-current state for obj or raise ReadConflictError."""
@@ -1108,7 +1107,7 @@
         for oid in oids:
             data, serial = src.load(oid, src)
             try:
-                blobfilename = src.loadBlob(oid, serial, self._version)
+                blobfilename = src.loadBlob(oid, serial)
             except POSKeyError:
                 s = self._storage.store(oid, serial, data,
                                         self._version, transaction)
@@ -1250,7 +1249,7 @@
         targetname = self._getCleanFilename(oid, serial)
         os.rename(blobfilename, targetname)
 
-    def loadBlob(self, oid, serial, version):
+    def loadBlob(self, oid, serial):
         """Return the filename where the blob file can be found.
         """
         filename = self._getCleanFilename(oid, serial)

Modified: ZODB/trunk/src/ZODB/ExportImport.py
===================================================================
--- ZODB/trunk/src/ZODB/ExportImport.py	2007-05-18 18:02:12 UTC (rev 75840)
+++ ZODB/trunk/src/ZODB/ExportImport.py	2007-05-18 18:02:14 UTC (rev 75841)
@@ -39,6 +39,7 @@
         done_oids = {}
         done=done_oids.has_key
         load=self._storage.load
+        supports_blobs = IBlobStorage.providedBy(self._storage)
         while oids:
             oid = oids.pop(0)
             if oid in done_oids:
@@ -52,20 +53,21 @@
             else:
                 referencesf(p, oids)
                 f.writelines([oid, p64(len(p)), p])
-            # Blob support
-            if not IBlobStorage.providedBy(self._storage):
-                continue
-            try:
-                blobfilename = self._storage.loadBlob(oid, 
-                                                      serial, self._version)
-            except POSKeyError: # Looks like this is not a blob
-                continue
 
-            f.write(blob_begin_marker)
-            f.write(p64(os.stat(blobfilename).st_size))
-            blobdata = open(blobfilename, "rb")
-            cp(blobdata, f)
-            blobdata.close()
+            if supports_blobs:
+                if 'Blob' not in p:
+                    continue # filter out most non-blobs
+                
+                blobfilename = self._storage.loadBlob(oid, serial)
+                if blobfilename is None:
+                    # This could be a non-blob or a blob with unsaved data.
+                    continue
+
+                f.write(blob_begin_marker)
+                f.write(p64(os.stat(blobfilename).st_size))
+                blobdata = open(blobfilename, "rb")
+                cp(blobdata, f)
+                blobdata.close()
             
         f.write(export_end_marker)
         return f



More information about the Zodb-checkins mailing list