[CMF-checkins] SVN: CMF/branches/1.6/C - fixed
IndexableObjectWrapper's __providedBy__ to allow the use of adapters
Yvo Schubbe
y.2006_ at wcm-solutions.de
Sun Apr 2 17:13:25 EDT 2006
Log message for revision 66324:
- fixed IndexableObjectWrapper's __providedBy__ to allow the use of adapters
- added some basic IndexableObjectWrapper tests
- removed obsolete manage_convertIndexes BBB method that might mask a newer version in Zope
Changed:
U CMF/branches/1.6/CHANGES.txt
U CMF/branches/1.6/CMFCore/CatalogTool.py
U CMF/branches/1.6/CMFCore/tests/test_CatalogTool.py
-=-
Modified: CMF/branches/1.6/CHANGES.txt
===================================================================
--- CMF/branches/1.6/CHANGES.txt 2006-04-02 17:00:12 UTC (rev 66323)
+++ CMF/branches/1.6/CHANGES.txt 2006-04-02 21:13:25 UTC (rev 66324)
@@ -1,3 +1,11 @@
+CMF 1.6.1-beta (unreleased)
+
+ Bug Fixes
+
+ - IndexableObjectWrapper: Fixed list of provided interfaces.
+ The interfaces declared for the wrapped object are no longer masked.
+
+
CMF 1.6.0 (2006/02/26)
Bug Fixes
Modified: CMF/branches/1.6/CMFCore/CatalogTool.py
===================================================================
--- CMF/branches/1.6/CMFCore/CatalogTool.py 2006-04-02 17:00:12 UTC (rev 66323)
+++ CMF/branches/1.6/CMFCore/CatalogTool.py 2006-04-02 21:13:25 UTC (rev 66324)
@@ -27,6 +27,10 @@
from Products.ZCTextIndex.Lexicon import Splitter
from Products.ZCTextIndex.Lexicon import StopWordRemover
from Products.ZCTextIndex.ZCTextIndex import PLexicon
+from zope.interface import providedBy
+from zope.interface.declarations import getObjectSpecification
+from zope.interface.declarations import ObjectSpecification
+from zope.interface.declarations import ObjectSpecificationDescriptor
from ActionProviderBase import ActionProviderBase
from interfaces.portal_catalog \
@@ -44,14 +48,33 @@
from utils import UniqueObject
-class IndexableObjectWrapper:
+class IndexableObjectSpecification(ObjectSpecificationDescriptor):
+ def __get__(self, inst, cls=None):
+ if inst is None:
+ return getObjectSpecification(cls)
+ else:
+ provided = providedBy(inst._IndexableObjectWrapper__ob)
+ cls = type(inst)
+ return ObjectSpecification(provided, cls)
+
+
+class IndexableObjectWrapper(object):
+
__implements__ = IIndexableObjectWrapper
+ __providedBy__ = IndexableObjectSpecification()
def __init__(self, vars, ob):
self.__vars = vars
self.__ob = ob
+ def __str__(self):
+ try:
+ # __str__ is used to get the data of File objects
+ return self.__ob.__str__()
+ except AttributeError:
+ return object.__str__(self)
+
def __getattr__(self, name):
vars = self.__vars
if vars.has_key(name):
@@ -352,63 +375,4 @@
idxs = [i for i in idxs if i in valid_indexes]
self.catalog_object(object, uid, idxs, update_metadata)
- # BBB: for Zope 2.8.0
- # copied from revision 31005 of ZCatalog.py
- def manage_convertIndexes(self, REQUEST=None, RESPONSE=None, URL1=None):
- """Recreate indexes derived from UnIndex because the implementation of
- __len__ changed in Zope 2.8. Pre-Zope 2.7 installation used to implement
- __len__ as persistent attribute of the index instance which is totally
- incompatible with the new extension class implementation based on new-style
- classes.
- """
-
- LOG.info('Start migration of indexes for %s' % self.absolute_url(1))
-
- reindex_ids = []
-
- for idx in self.Indexes.objectValues():
- bases = [str(name) for name in idx.__class__.__bases__]
- found = False
-
- if idx.meta_type == 'PathIndex':
- found = True
- else:
- for base in bases:
- if 'UnIndex' in base:
- found = True
- break
-
- if found:
- idx_type = idx.meta_type
- idx_id = idx.getId()
- LOG.info('processing index %s' % idx_id)
-
- indexed_attrs = getattr(idx, 'indexed_attrs', None)
-
- if idx.meta_type == 'DateRangeIndex':
- since_field = getattr(idx, '_since_field', None)
- until_field = getattr(idx, '_until_field', None)
-
- self.delIndex(idx.getId())
- self.addIndex(idx_id, idx_type)
- new_idx = self.Indexes[idx_id]
-
- if indexed_attrs:
- setattr(new_idx, 'indexed_attrs', indexed_attrs)
- if idx.meta_type == 'DateRangeIndex':
- setattr(new_idx, '_since_field', since_field)
- setattr(new_idx, '_until_field', until_field)
- reindex_ids.append(idx_id)
-
- if reindex_ids:
- LOG.info('Reindexing %s' % ', '.join(reindex_ids))
- self.manage_reindexIndex(reindex_ids, REQUEST)
-
- self._migrated_280 = True
- LOG.info('Finished migration of indexes for %s' % self.absolute_url(1))
-
- if RESPONSE:
- RESPONSE.redirect( URL1 +
- '/manage_main?manage_tabs_message=Indexes%20converted%20and%20reindexed')
-
InitializeClass(CatalogTool)
Modified: CMF/branches/1.6/CMFCore/tests/test_CatalogTool.py
===================================================================
--- CMF/branches/1.6/CMFCore/tests/test_CatalogTool.py 2006-04-02 17:00:12 UTC (rev 66323)
+++ CMF/branches/1.6/CMFCore/tests/test_CatalogTool.py 2006-04-02 21:13:25 UTC (rev 66324)
@@ -15,12 +15,9 @@
$Id$
"""
-from unittest import TestCase, TestSuite, makeSuite, main
+import unittest
import Testing
-try:
- import Zope2
-except ImportError: # BBB: for Zope 2.7
- import Zope as Zope2
+import Zope2
Zope2.startup()
from AccessControl.SecurityManagement import newSecurityManager
@@ -33,60 +30,93 @@
from Products.CMFCore.tests.base.testcase import SecurityTest
-class IndexableObjectWrapperTests(TestCase):
+class IndexableObjectWrapperTests(unittest.TestCase):
+ def _getTargetClass(self):
+ from Products.CMFCore.CatalogTool import IndexableObjectWrapper
+
+ return IndexableObjectWrapper
+
+ def _makeOne(self, *args, **kw):
+ return self._getTargetClass()(*args, **kw)
+
def test_z2interfaces(self):
from Interface.Verify import verifyClass
- from Products.CMFCore.CatalogTool import IndexableObjectWrapper
from Products.CMFCore.interfaces.portal_catalog \
import IndexableObjectWrapper as IIndexableObjectWrapper
- verifyClass(IIndexableObjectWrapper, IndexableObjectWrapper)
+ verifyClass(IIndexableObjectWrapper, self._getTargetClass())
def test_z3interfaces(self):
- try:
- from zope.interface.verify import verifyClass
- from Products.CMFCore.interfaces import IIndexableObjectWrapper
- except ImportError:
- # BBB: for Zope 2.7
- return
- from Products.CMFCore.CatalogTool import IndexableObjectWrapper
+ from zope.interface.verify import verifyClass
+ from Products.CMFCore.interfaces import IIndexableObjectWrapper
- verifyClass(IIndexableObjectWrapper, IndexableObjectWrapper)
+ verifyClass(IIndexableObjectWrapper, self._getTargetClass())
+ def test_allowedRolesAndUsers(self):
+ obj = DummyContent()
+ w = self._makeOne({}, obj)
+ self.assertEqual(w.allowedRolesAndUsers(), ['Manager'])
+ def test___str__(self):
+ obj = DummyContent('foo')
+ w = self._makeOne({}, obj)
+ self.assertEqual(str(w), str(obj))
+
+ def test_proxied_attributes(self):
+ obj = DummyContent('foo')
+ obj.title = 'Foo'
+ w = self._makeOne({}, obj)
+ self.assertEqual(w.getId(), 'foo')
+ self.assertEqual(w.Title(), 'Foo')
+
+ def test_vars(self):
+ obj = DummyContent()
+ w = self._makeOne({'bar': 1, 'baz': 2}, obj)
+ self.assertEqual(w.bar, 1)
+ self.assertEqual(w.baz, 2)
+
+ def test_provided(self):
+ from Products.CMFCore.interfaces import IContentish
+ from Products.CMFCore.interfaces import IIndexableObjectWrapper
+
+ obj = DummyContent()
+ w = self._makeOne({}, obj)
+ self.failUnless(IContentish.providedBy(w))
+ self.failUnless(IIndexableObjectWrapper.providedBy(w))
+
+
class CatalogToolTests(SecurityTest):
- def _makeOne(self, *args, **kw):
+ def _getTargetClass(self):
from Products.CMFCore.CatalogTool import CatalogTool
- return CatalogTool(*args, **kw)
+ return CatalogTool
+ def _makeOne(self, *args, **kw):
+ return self._getTargetClass()(*args, **kw)
+
def test_z2interfaces(self):
from Interface.Verify import verifyClass
- from Products.CMFCore.CatalogTool import CatalogTool
from Products.CMFCore.interfaces.portal_actions \
import ActionProvider as IActionProvider
from Products.CMFCore.interfaces.portal_catalog \
import portal_catalog as ICatalogTool
from Products.ZCatalog.IZCatalog import IZCatalog
- verifyClass(IActionProvider, CatalogTool)
- verifyClass(ICatalogTool, CatalogTool)
- verifyClass(IZCatalog, CatalogTool)
+ verifyClass(IActionProvider, self._getTargetClass())
+ verifyClass(ICatalogTool, self._getTargetClass())
+ verifyClass(IZCatalog, self._getTargetClass())
def test_z3interfaces(self):
- try:
- from zope.interface.verify import verifyClass
- from Products.CMFCore.interfaces import IActionProvider
- from Products.CMFCore.interfaces import ICatalogTool
- except ImportError:
- # BBB: for Zope 2.7
- return
- from Products.CMFCore.CatalogTool import CatalogTool
+ from zope.interface.verify import verifyClass
+ from Products.CMFCore.interfaces import IActionProvider
+ from Products.CMFCore.interfaces import ICatalogTool
+ from Products.ZCatalog.interfaces import IZCatalog
- verifyClass(IActionProvider, CatalogTool)
- verifyClass(ICatalogTool, CatalogTool)
+ verifyClass(IActionProvider, self._getTargetClass())
+ verifyClass(ICatalogTool, self._getTargetClass())
+ verifyClass(IZCatalog, self._getTargetClass())
def loginWithRoles(self, *roles):
user = UserWithRoles(*roles).__of__(self.root)
@@ -317,10 +347,10 @@
def test_suite():
- return TestSuite((
- makeSuite(IndexableObjectWrapperTests),
- makeSuite(CatalogToolTests),
+ return unittest.TestSuite((
+ unittest.makeSuite(IndexableObjectWrapperTests),
+ unittest.makeSuite(CatalogToolTests),
))
if __name__ == '__main__':
- main(defaultTest='test_suite')
+ unittest.main(defaultTest='test_suite')
More information about the CMF-checkins
mailing list