[Checkins] SVN: z3c.blobfile/trunk/ Add zope.copy hook to fix blobfile copying.

Dan Korostelev nadako at gmail.com
Tue Mar 3 11:25:49 EST 2009


Log message for revision 97443:
  Add zope.copy hook to fix blobfile copying.

Changed:
  U   z3c.blobfile/trunk/CHANGES.txt
  U   z3c.blobfile/trunk/buildout.cfg
  U   z3c.blobfile/trunk/setup.py
  U   z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt
  U   z3c.blobfile/trunk/src/z3c/blobfile/configure.zcml
  A   z3c.blobfile/trunk/src/z3c/blobfile/copy.py

-=-
Modified: z3c.blobfile/trunk/CHANGES.txt
===================================================================
--- z3c.blobfile/trunk/CHANGES.txt	2009-03-03 16:21:03 UTC (rev 97442)
+++ z3c.blobfile/trunk/CHANGES.txt	2009-03-03 16:25:48 UTC (rev 97443)
@@ -2,12 +2,15 @@
 CHANGES
 =======
 
-Version 0.1.4 (unreleased)
+0.1.4 (unreleased)
+------------------
 
--
+- Add copy hook for zope.copy to fix blob file/image copying.
+- Change package's mailing list address to zope-dev at zope.org
+  instead of retired zope3-dev. 
 
-Version 0.1.3 (2008-10-20)
---------------------------
+0.1.3 (2008-10-20)
+------------------
 
 - Bug: Don't get/set image data twice on Image initialization.
 - Cache file size and invalidate it on write access.
@@ -15,16 +18,16 @@
   read-only file-like access to the blob, detached from the database
   connection.
 
-Version 0.1.2 (2008-09-11)
---------------------------
+0.1.2 (2008-09-11)
+------------------
 
 - Bug: Set i18n domain in "overrides.zcml" to avoid warnings.
 - Don't expose Blob implementation details in add/upload forms. Also, "zope"
   translation domain has no translations for "Upload a File (Blob)", it just
   has "Upload a File" translations, so use it.
 
-Version 0.1.1 (2008-09-08)
---------------------------
+0.1.1 (2008-09-08)
+------------------
 
 - Bug: Register zope.app.wsgi.fileresult.FileResult as an adapter for BlobFile,
   making optimized file views really work.
@@ -33,7 +36,7 @@
   IBlobImage interfaces respectively. This enables z3c.blobfile's views.
 - Bug: Use local ZopeMessageFactory. This fixes import error on Zope 2.10
 
-Version 0.1.0 (2008-02-27)
---------------------------
+0.1.0 (2008-02-27)
+------------------
 
 - Initial Release

Modified: z3c.blobfile/trunk/buildout.cfg
===================================================================
--- z3c.blobfile/trunk/buildout.cfg	2009-03-03 16:21:03 UTC (rev 97442)
+++ z3c.blobfile/trunk/buildout.cfg	2009-03-03 16:25:48 UTC (rev 97443)
@@ -1,10 +1,15 @@
 [buildout]
-index = http://download.zope.org/zope3.4
 develop = .
 parts = test
+versions = versions
 
+# with zodb 3.9, DemoStorage currently fails with _tid attribute, so
+# nail ZODB version to 3.8.1 for tests.
+[versions]
+ZODB3 = 3.8.1
+
 [test]
 recipe = zc.recipe.testrunner
 eggs = z3c.blobfile [test]
 zcml = z3c.blobfile-overrides
-defaults = ['--tests-pattern', '^f?tests$', '-v']
\ No newline at end of file
+defaults = ['--tests-pattern', '^f?tests$', '-v']

Modified: z3c.blobfile/trunk/setup.py
===================================================================
--- z3c.blobfile/trunk/setup.py	2009-03-03 16:21:03 UTC (rev 97442)
+++ z3c.blobfile/trunk/setup.py	2009-03-03 16:25:48 UTC (rev 97443)
@@ -24,7 +24,7 @@
 setup(name='z3c.blobfile',
       version='0.1.4dev',
       author = "Zope Community",
-      author_email = "zope3-dev at zope.org",
+      author_email = "zope-dev at zope.org",
       license = "ZPL 2.1",
       keywords = "zope3 ZODB blob file image content",
       url='http://pypi.python.org/pypi/z3c.blobfile',
@@ -74,6 +74,7 @@
                         'zope.schema',
                         'zope.size',
                         'zope.app.file',
+                        'zope.copy',
                         
                         ],
       include_package_data = True,

Modified: z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt
===================================================================
--- z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt	2009-03-03 16:21:03 UTC (rev 97442)
+++ z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt	2009-03-03 16:25:48 UTC (rev 97443)
@@ -219,3 +219,26 @@
     >>> root[u'file']._data
     'A text file'
     
+
+Copying
+-------
+
+Let's check that blob files can be copied successfully. This
+functionality requires the new "zope.copy" package and the
+version of zope.copypastemove that uses zope.copy (>=3.5.1).
+
+    >>> from zope.copy import copy
+    >>> file = z3c.blobfile.file.File()
+    >>> file.data = u'hello, world'
+    >>> image = z3c.blobfile.file.File()
+    >>> image.data = 'some image bytes'
+    >>> transaction.commit()
+
+    >>> file_copy = copy(file)
+    >>> file_copy.data == file.data
+    True
+
+    >>> image_copy = copy(image)
+    >>> image_copy.data == image.data
+    True
+    
\ No newline at end of file

Modified: z3c.blobfile/trunk/src/z3c/blobfile/configure.zcml
===================================================================
--- z3c.blobfile/trunk/src/z3c/blobfile/configure.zcml	2009-03-03 16:21:03 UTC (rev 97442)
+++ z3c.blobfile/trunk/src/z3c/blobfile/configure.zcml	2009-03-03 16:25:48 UTC (rev 97443)
@@ -108,9 +108,11 @@
       permission="zope.ManageContent"
       />
 
+  <adapter factory=".copy.BlobFileCopyHook" />
+
   <!-- TODO: have a look later
   <adapter
-      for="zope.app.folder.interfaces.IFolder"
+      for="zope.site.interfaces.IFolder"
       provides="zope.filerepresentation.interfaces.IFileFactory"
       factory=".image.FileFactory"
       permission="zope.ManageContent"

Added: z3c.blobfile/trunk/src/z3c/blobfile/copy.py
===================================================================
--- z3c.blobfile/trunk/src/z3c/blobfile/copy.py	                        (rev 0)
+++ z3c.blobfile/trunk/src/z3c/blobfile/copy.py	2009-03-03 16:25:48 UTC (rev 97443)
@@ -0,0 +1,46 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Copy hook for proper copying blob data
+
+$Id$
+"""
+import shutil
+
+from ZODB.blob import Blob
+from zope.component import adapts
+from zope.interface import implements
+from zope.copy.interfaces import ICopyHook, ResumeCopy
+from z3c.blobfile.interfaces import IBlobFile
+
+class BlobFileCopyHook(object):
+    """A copy hook that fixes the blob after copying"""
+
+    implements(ICopyHook)
+    adapts(IBlobFile)
+
+    def __init__(self, context):
+        self.context = context
+
+    def __call__(self, toplevel, register):
+        register(self._copyBlob)
+        raise ResumeCopy
+
+    def _copyBlob(self, translate):
+        target = translate(self.context)
+        target._blob = Blob()
+        fsrc = self.context._blob.open('r')
+        fdst = target._blob.open('w')
+        shutil.copyfileobj(fsrc, fdst)
+        fdst.close()
+        fsrc.close()


Property changes on: z3c.blobfile/trunk/src/z3c/blobfile/copy.py
___________________________________________________________________
Added: svn:keywords
   + Id,svn:eol-style=native



More information about the Checkins mailing list