r974 - in /zope-pluginregistry/branches/upstream/current: CHANGES.txt PluginRegistry.py exportimport.py tests/test_PluginRegistry.py tests/test_exportimport.py version.txt

bzed-guest at users.alioth.debian.org bzed-guest at users.alioth.debian.org
Tue Aug 7 22:56:04 UTC 2007


Author: bzed-guest
Date: Tue Aug  7 22:56:04 2007
New Revision: 974

URL: http://svn.debian.org/wsvn/pkg-zope/?sc=1&rev=974
Log:
[svn-upgrade] Integrating new upstream version, zope-pluginregistry (1.1.2)

Modified:
    zope-pluginregistry/branches/upstream/current/CHANGES.txt
    zope-pluginregistry/branches/upstream/current/PluginRegistry.py
    zope-pluginregistry/branches/upstream/current/exportimport.py
    zope-pluginregistry/branches/upstream/current/tests/test_PluginRegistry.py
    zope-pluginregistry/branches/upstream/current/tests/test_exportimport.py
    zope-pluginregistry/branches/upstream/current/version.txt

Modified: zope-pluginregistry/branches/upstream/current/CHANGES.txt
URL: http://svn.debian.org/wsvn/pkg-zope/zope-pluginregistry/branches/upstream/current/CHANGES.txt?rev=974&op=diff
==============================================================================
--- zope-pluginregistry/branches/upstream/current/CHANGES.txt (original)
+++ zope-pluginregistry/branches/upstream/current/CHANGES.txt Tue Aug  7 22:56:04 2007
@@ -1,4 +1,15 @@
 PluginRegistry Product Changelog
+
+  PluginRegistry 1.1.2 (2007/04/24)
+
+    - Drop previously-activated plugins from the list returned from
+      'listPlugins' when they no longer implement the plugin interface.
+      (http://www.zope.org/Collectors/PAS/53)
+
+    - Skip adding duplicate interfaces during non-purge import.
+      (http://www.zope.org/Collectors/PAS/52)
+
+    - Fixed test breakage on Zope 2.10.
 
   PluginRegistry 1.1.1 (2006/07/25)
 

Modified: zope-pluginregistry/branches/upstream/current/PluginRegistry.py
URL: http://svn.debian.org/wsvn/pkg-zope/zope-pluginregistry/branches/upstream/current/PluginRegistry.py?rev=974&op=diff
==============================================================================
--- zope-pluginregistry/branches/upstream/current/PluginRegistry.py (original)
+++ zope-pluginregistry/branches/upstream/current/PluginRegistry.py Tue Aug  7 22:56:04 2007
@@ -14,8 +14,9 @@
 ##############################################################################
 """ Classes: PluginRegistry
 
-$Id: PluginRegistry.py 69261 2006-07-25 22:09:23Z tseaver $
+$Id: PluginRegistry.py 74716 2007-04-24 19:15:04Z tseaver $
 """
+import logging
 
 from Globals import Persistent
 from App.ImageFile import ImageFile
@@ -57,6 +58,8 @@
 
 from utils import _wwwdir
 
+logger = logging.getLogger('PluginRegistry')
+
 class PluginRegistry( SimpleItem ):
 
     """ Implement IPluginRegistry as an independent, ZMI-manageable object.
@@ -125,7 +128,12 @@
         for plugin_id in self._getPlugins( plugin_type ):
 
             plugin = parent._getOb( plugin_id )
-            result.append( ( plugin_id, plugin ) )
+            if not _satisfies( plugin, plugin_type ):
+                logger.debug( 'Active plugin %s no longer implements %s'
+                                % ( plugin_id, plugin_type )
+                            )
+            else:
+                result.append( ( plugin_id, plugin ) )
 
         return result
 
@@ -158,11 +166,7 @@
         parent = aq_parent( aq_inner( self ) )
         plugin = parent._getOb( plugin_id ) 
 
-        satisfies = getattr(plugin_type, 'providedBy', None)
-        if satisfies is None:
-            satisfies = plugin_type.isImplementedBy
-
-        if not satisfies(plugin):
+        if not _satisfies(plugin, plugin_type):
             raise ValueError, 'Plugin does not implement %s' % plugin_type 
         
         plugins.append( plugin_id )
@@ -311,12 +315,8 @@
         active = self._getPlugins( interface )
         available = []
 
-        satisfies = getattr(interface, 'providedBy', None)
-        if satisfies is None:
-            satisfies = interface.isImplementedBy
-
         for id, value in aq_parent( aq_inner( self ) ).objectItems():
-            if satisfies( value ):
+            if _satisfies(value, interface):
                 if id not in active:
                     available.append( id )
 
@@ -428,6 +428,13 @@
 
 InitializeClass( PluginRegistry )
 
+def _satisfies( plugin, iface ):
+    checker = getattr(iface, 'providedBy', None)
+    if checker is None: # BBB for Zope 2.7?
+        checker = iface.isImplementedBy
+
+    return checker(plugin)
+
 def emptyPluginRegistry( ignored ):
     """ Return empty registry, for filling from setup profile.
     """

Modified: zope-pluginregistry/branches/upstream/current/exportimport.py
URL: http://svn.debian.org/wsvn/pkg-zope/zope-pluginregistry/branches/upstream/current/exportimport.py?rev=974&op=diff
==============================================================================
--- zope-pluginregistry/branches/upstream/current/exportimport.py (original)
+++ zope-pluginregistry/branches/upstream/current/exportimport.py Tue Aug  7 22:56:04 2007
@@ -14,7 +14,7 @@
 ##############################################################################
 """ GenericSetup export / import support for PluginRegistry.
 
-$Id: exportimport.py 40099 2005-11-14 20:48:24Z tseaver $
+$Id: exportimport.py 74714 2007-04-24 18:21:57Z tseaver $
 """
 from StringIO import StringIO
 
@@ -81,7 +81,9 @@
 
     for info in reg_info['plugin_types']:
         iface = _resolveDottedName(info['interface'])
-        registry._plugin_types.append(iface)
+        # Avoid duplicate plugin types
+        if iface not in registry._plugin_types:
+            registry._plugin_types.append(iface)
         registry._plugin_type_info[iface] = {'id': info['id'],
                                              'title': info['title'],
                                              'description': info['description'],

Modified: zope-pluginregistry/branches/upstream/current/tests/test_PluginRegistry.py
URL: http://svn.debian.org/wsvn/pkg-zope/zope-pluginregistry/branches/upstream/current/tests/test_PluginRegistry.py?rev=974&op=diff
==============================================================================
--- zope-pluginregistry/branches/upstream/current/tests/test_PluginRegistry.py (original)
+++ zope-pluginregistry/branches/upstream/current/tests/test_PluginRegistry.py Tue Aug  7 22:56:04 2007
@@ -69,7 +69,6 @@
 
         verifyClass( IPluginRegistry, self._getTargetClass() )
 
-
     def test_empty( self ):
 
         preg = self._makeOne()
@@ -121,14 +120,32 @@
         self.assertEqual( len( idlist ), 1 )
         self.assertEqual( idlist[0], 'foo_plugin' )
 
-        # XXX:  Note that we aren't testing 'listPlugins' here, as it
-        #       requires that we have TALES wired up.
-        #
-        #plugins = preg.listPlugins( 'foo' )
-        #self.assertEqual( len( plugins ), 1 )
-        #plugin = plugins[0]
-        #self.assertEqual( plugin[0], 'test' )
-        #self.assertEqual( plugin[1], preg.test_foo )
+        plugins = preg.listPlugins( IFoo )
+        self.assertEqual( len( plugins ), 1 )
+        plugin = plugins[0]
+        self.assertEqual( plugin[0], 'foo_plugin' )
+        self.assertEqual( plugin[1], preg.foo_plugin )
+
+    def test_activatePlugin_then_remove_interface( self ):
+
+        parent = DummyFolder()
+        foo_plugin = DummyPlugin()
+        directlyProvides( foo_plugin,  ( IFoo, ) )
+        parent._setObject( 'foo_plugin', foo_plugin )
+
+        preg = self._makeOne().__of__(parent)
+
+        preg.activatePlugin( IFoo, 'foo_plugin')
+
+        replacement = DummyPlugin()
+        parent._delObject( 'foo_plugin' )
+        parent._setObject( 'foo_plugin', replacement )
+
+        idlist = preg.listPluginIds( IFoo )
+        self.assertEqual( len( idlist ), 1 )  # note discrepancy
+
+        plugins = preg.listPlugins( IFoo )
+        self.assertEqual( len( plugins ), 0 )
 
     def test_deactivatePlugin( self ):
 

Modified: zope-pluginregistry/branches/upstream/current/tests/test_exportimport.py
URL: http://svn.debian.org/wsvn/pkg-zope/zope-pluginregistry/branches/upstream/current/tests/test_exportimport.py?rev=974&op=diff
==============================================================================
--- zope-pluginregistry/branches/upstream/current/tests/test_exportimport.py (original)
+++ zope-pluginregistry/branches/upstream/current/tests/test_exportimport.py Tue Aug  7 22:56:04 2007
@@ -14,7 +14,7 @@
 ##############################################################################
 """ Unit tests for GenericSetup-based export / import of PluginRegistry.
 
-$Id: test_exportimport.py 68733 2006-06-18 11:44:00Z jens $
+$Id: test_exportimport.py 74716 2007-04-24 19:15:04Z tseaver $
 """
 import unittest
 
@@ -33,6 +33,17 @@
     from Products.GenericSetup.utils import _getDottedName
 
     from zope.interface import Interface
+    from zope.interface import directlyProvides
+    from zope.app.testing import ztapi
+
+    try:
+        from zope.traversing.interfaces import ITraversable
+        from zope.traversing.interfaces import TraversalError
+    except ImportError:
+        # BBB for Zope 2.9
+        from zope.app.traversing.interfaces import ITraversable
+        from zope.app.traversing.interfaces import TraversalError
+
     try:
         from zope.app.testing.placelesssetup import PlacelessSetup
     except ImportError:
@@ -120,6 +131,9 @@
             registry._plugins = {} # it is usually lazy
 
             for plugin_type, registered in plugins.items():
+                for obj_id in registered:
+                    obj = app._getOb(obj_id)
+                    directlyProvides(obj, plugin_type)
                 registry._plugins[plugin_type] = registered
 
             app._setObject('plugin_registry', registry)
@@ -134,6 +148,7 @@
             return PluginRegistryExporter
 
         def test_empty(self):
+            ztapi.provideAdapter(None, ITraversable, AttrItemTraverser)
 
             app, registry = self._initRegistry()
             exporter = self._makeOne(registry).__of__(registry)
@@ -142,6 +157,8 @@
             self._compareDOM(xml, _EMPTY_PLUGINREGISTRY_EXPORT)
 
         def test_normal_no_plugins(self):
+            ztapi.provideAdapter(None, ITraversable, AttrItemTraverser)
+
             app, registry = self._initRegistry(
                                     plugin_type_info=_PLUGIN_TYPE_INFO)
             exporter = self._makeOne(registry).__of__(registry)
@@ -150,6 +167,8 @@
             self._compareDOM(xml, _NO_PLUGINS_PLUGINREGISTRY_EXPORT)
 
         def test_normal_with_plugins(self):
+            ztapi.provideAdapter(None, ITraversable, AttrItemTraverser)
+
             app, registry = self._initRegistry(
                                     plugin_type_info=_PLUGIN_TYPE_INFO,
                                     plugins={IFoo: ('foo_plugin_1',
@@ -165,6 +184,7 @@
         def test_empty(self):
             from Products.PluginRegistry.exportimport \
                 import exportPluginRegistry
+            ztapi.provideAdapter(None, ITraversable, AttrItemTraverser)
 
             app, registry = self._initRegistry()
             context = DummyExportContext(app)
@@ -179,6 +199,7 @@
         def test_normal_no_plugins(self):
             from Products.PluginRegistry.exportimport \
                 import exportPluginRegistry
+            ztapi.provideAdapter(None, ITraversable, AttrItemTraverser)
 
             app, registry = self._initRegistry(
                                     plugin_type_info=_PLUGIN_TYPE_INFO)
@@ -194,6 +215,7 @@
         def test_normal_with_plugins(self):
             from Products.PluginRegistry.exportimport \
                 import exportPluginRegistry
+            ztapi.provideAdapter(None, ITraversable, AttrItemTraverser)
 
             app, registry = self._initRegistry(
                                     plugin_type_info=_PLUGIN_TYPE_INFO,
@@ -346,7 +368,9 @@
             from Products.PluginRegistry.exportimport \
                 import importPluginRegistry
 
-            app, registry = self._initRegistry()
+            app, registry = self._initRegistry(plugins={IFoo: ('foo_plugin_1',
+                                                               'foo_plugin_2')},
+                                              )
 
             self.assertEqual(len(registry.listPluginTypeInfo()), 0)
             self.assertRaises(KeyError, registry.listPlugins, IFoo)
@@ -377,7 +401,9 @@
             from Products.PluginRegistry.exportimport \
                 import importPluginRegistry
 
-            app, registry = self._initRegistry()
+            app, registry = self._initRegistry(plugins={IFoo: ('foo_plugin_1',
+                                                               'foo_plugin_2')},
+                                              )
 
             self.assertEqual(len(registry.listPluginTypeInfo()), 0)
             self.assertRaises(KeyError, registry.listPlugins, IFoo)
@@ -409,6 +435,43 @@
             self.assertEqual(plugins[1][1], app._getOb('foo_plugin_2'))
 
             self.assertEqual(len(registry.listPlugins(IBar)), 0)
+
+        def test_normal_with_plugins_skip_duplicates(self):
+            # See http://www.zope.org/Collectors/PAS/52
+            from Products.PluginRegistry.exportimport \
+                import importPluginRegistry
+
+            app, registry = self._initRegistry()
+
+            self.assertEqual(len(registry.listPluginTypeInfo()), 0)
+            self.assertRaises(KeyError, registry.listPlugins, IFoo)
+            self.assertRaises(KeyError, registry.listPlugins, IBar)
+
+            context = DummyImportContext(app, False)
+            context._files['pluginregistry.xml'
+                          ] = _NORMAL_PLUGINREGISTRY_EXPORT
+
+            importPluginRegistry(context)
+            importPluginRegistry(context) # twice should not duplicate
+
+            self.assertEqual(len(registry.listPluginTypeInfo()), 2)
+
+    class AttrItemTraverser:
+        _marker = object()
+
+        def __init__(self, context):
+            self.context = context
+
+        def traverse(self, name, furtherPath):
+            result = getattr(self.context, name, self._marker)
+            if result is self._marker:
+                try:
+                    result = self.context.get(name, self._marker)
+                except AttributeError:
+                    pass
+            if result is self._marker:
+                raise TraversalError(name)
+            return result
 
     def test_suite():
         return unittest.TestSuite((

Modified: zope-pluginregistry/branches/upstream/current/version.txt
URL: http://svn.debian.org/wsvn/pkg-zope/zope-pluginregistry/branches/upstream/current/version.txt?rev=974&op=diff
==============================================================================
--- zope-pluginregistry/branches/upstream/current/version.txt (original)
+++ zope-pluginregistry/branches/upstream/current/version.txt Tue Aug  7 22:56:04 2007
@@ -1,1 +1,1 @@
-1.1.1
+1.1.2




More information about the pkg-zope-commits mailing list