[Checkins] SVN: z3c.blobfile/trunk/src/z3c/blobfile/ Added warnings
for unsupported IFile implementations.
Uwe Oestermeier
u.oestermeier at iwm-kmrc.de
Wed Nov 14 11:06:33 EST 2007
Log message for revision 81841:
Added warnings for unsupported IFile implementations.
Changed:
U z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt
U z3c.blobfile/trunk/src/z3c/blobfile/generations/evolve1.py
U z3c.blobfile/trunk/src/z3c/blobfile/testing.py
-=-
Modified: z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt
===================================================================
--- z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt 2007-11-14 15:24:32 UTC (rev 81840)
+++ z3c.blobfile/trunk/src/z3c/blobfile/blobfile.txt 2007-11-14 16:06:32 UTC (rev 81841)
@@ -14,17 +14,28 @@
>>> from z3c.blobfile import testing
>>> root[u'file'] = File('A text file', contentType='text/plain')
>>> root[u'image'] = Image(testing.zptlogo)
+
+Since the evolve step looks for implementations of IFile we also must
+provide a way to recognize other implementations than zope.app.file.File and
+Image. Let's add a nonsense implementation as an example:
+
+ >>> root[u'custom'] = testing.MyFile()
Note that we cannot assume that these objects exist in isolation. Many of
them probably are annotated, indexed, some even may be registered as utility
etc.
Therefore we need a very conservative evolution strategy. We simply replace
-the __class__ attribute and the data section. We will not test all relations
-to all other objects, since this is largely application dependent. Here
-we only take the ZopeDublinCore timestamps as an example that our evolution
-step leaves as many things untouched as possible.
+the __class__ attribute and the data section.
+IMPORTANT: If your application needs to be aware of the hidden type change,
+you must provide your own evolution procedure.
+
+
+We will not test all relations to all other objects, since this is largely
+application dependent. Here we only take the ZopeDublinCore timestamps as
+an example that our evolution step leaves as many things untouched as possible.
+
>>> from zope.dublincore.interfaces import IZopeDublinCore
>>> import datetime
@@ -32,10 +43,19 @@
>>> t1 = IZopeDublinCore(root[u'file']).created
>>> IZopeDublinCore(root[u'file']).title = u'No evolution'
-Now we perform the basic evolution steps:
+Now we perform the basic evolution steps. Since we expect some warning logs
+we need
+
+ >>> from zope.testing.loggingsupport import InstalledHandler
+ >>> import logging
+ >>> log_handler = InstalledHandler('z3c.blobfile.generations')
>>> from z3c.blobfile.generations.evolve1 import evolveZopeAppFile
>>> evolveZopeAppFile(root)
+
+ >>> for record in log_handler.records:
+ ... print record.getMessage()
+ Unknown ...interfaces.IFile implementation z3c.blobfile.testing.MyFile
The file data remain the same ...
@@ -54,14 +74,10 @@
>>> IZopeDublinCore(root[u'file']).title
u'No evolution'
-IMPORTANT: If your application needs to be aware of the hidden type change,
-you must provide your own evolution procedure.
-
Adding Blob Files
-----------------
-
>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
Modified: z3c.blobfile/trunk/src/z3c/blobfile/generations/evolve1.py
===================================================================
--- z3c.blobfile/trunk/src/z3c/blobfile/generations/evolve1.py 2007-11-14 15:24:32 UTC (rev 81840)
+++ z3c.blobfile/trunk/src/z3c/blobfile/generations/evolve1.py 2007-11-14 16:06:32 UTC (rev 81841)
@@ -1,3 +1,4 @@
+import logging
import zope.interface
import zope.component
@@ -20,16 +21,22 @@
"""
for file in findObjectsProviding(root, IFile):
data = file.data
-
file._blob = Blob()
if isinstance(file, zope.app.file.File):
file.__class__ = z3c.blobfile.file.File
-
+ file.data = data
+ continue
+
if isinstance(file, zope.app.file.Image):
- file.__class__ = z3c.blobfile.image.Image
-
- file.data = data
+ file.__class__ = z3c.blobfile.image.Image
+ file.data = data
+ continue
+
+ logging.getLogger('z3c.blobfile.generations').warn(
+ 'Unknown zope.app.file.interfaces.IFile implementation %s.%s' % (
+ file.__class__.__module__,
+ file.__class__.__name__))
def evolve(context):
Modified: z3c.blobfile/trunk/src/z3c/blobfile/testing.py
===================================================================
--- z3c.blobfile/trunk/src/z3c/blobfile/testing.py 2007-11-14 15:24:32 UTC (rev 81840)
+++ z3c.blobfile/trunk/src/z3c/blobfile/testing.py 2007-11-14 16:06:32 UTC (rev 81841)
@@ -21,13 +21,17 @@
import os.path
import shutil
import tempfile
-
+import persistent
import transaction
from ZODB.DB import DB
from ZODB.DemoStorage import DemoStorage
from ZODB.blob import BlobStorage
+
+import zope.interface
from zope.testing import doctest
import zope.app.testing.functional
+import zope.app.file.interfaces
+
from zope.app.component.hooks import setSite
here = os.path.dirname(os.path.realpath(__file__))
@@ -52,6 +56,12 @@
'\x00A\x00;'
)
+class MyFile(persistent.Persistent):
+ zope.interface.implements(zope.app.file.interfaces.IFile)
+
+ data = 'My data'
+ contentType = 'text/plain'
+
class FunctionalBlobTestSetup(zope.app.testing.functional.FunctionalTestSetup):
temp_dir_name = None
More information about the Checkins
mailing list