[Zope3-checkins] CVS: Zope3/src/zope/app/dublincore -
annotatableadapter.py:1.4
Fred L. Drake, Jr.
fred at zope.com
Tue Aug 19 16:01:57 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/dublincore
In directory cvs.zope.org:/tmp/cvs-serv1836
Modified Files:
annotatableadapter.py
Log Message:
Use a distinct type for the Dublin Core metadata, and provide a
slightly simpler fssync serialization (a pickled dict instead of a
pickled persistent dict). Old pickles are still accepted. When the
data is stored in the base PersistentDict, it will be upgraded on the
first write.
=== Zope3/src/zope/app/dublincore/annotatableadapter.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/dublincore/annotatableadapter.py:1.3 Mon Dec 30 16:42:28 2002
+++ Zope3/src/zope/app/dublincore/annotatableadapter.py Tue Aug 19 15:01:52 2003
@@ -18,9 +18,13 @@
__metaclass__ = type
from zope.component import getAdapter
+from zope.interface import implements
from zope.app.interfaces.annotation import IAnnotations
from zope.app.interfaces.annotation import IAnnotatable
+from zope.app.interfaces.fssync import IObjectFile
from zope.app.dublincore.zopedublincore import ZopeDublinCore
+from zope.app.fssync.classes import ObjectEntryAdapter
+from zope.xmlpickle import dumps, loads
from persistence.dict import PersistentDict
DCkey = "zope.app.dublincore.ZopeDublinCore"
@@ -37,7 +41,16 @@
dcdata = annotations.get(DCkey)
if not dcdata:
self.annotations = annotations
- dcdata = PersistentDict()
+ dcdata = ZDCAnnotationData()
+ elif not isinstance(dcdata, ZDCAnnotationData):
+ # Convert mapping to a ZDCAnnotationData, and set things
+ # up so that the annotations object is only updated the
+ # first time we're writing to it; this avoids converting
+ # it when we wouldn't otherwise write to the object.
+ self.annotations = annotations
+ d = ZDCAnnotationData()
+ d.update(dcdata)
+ dcdata = d
super(ZDCAnnotatableAdapter, self).__init__(dcdata)
@@ -47,3 +60,20 @@
self.annotations = None
__doc__ = ZDCAnnotatableAdapter.__doc__ + __doc__
+
+
+class ZDCAnnotationData(PersistentDict):
+ pass
+
+
+class ZDCAnnotationDataAdapter(ObjectEntryAdapter):
+
+ implements(IObjectFile)
+
+ def getBody(self):
+ return dumps(self.context.data)
+
+ def setBody(self, data):
+ data = loads(data)
+ self.context.clear()
+ self.context.update(data)
More information about the Zope3-Checkins
mailing list