[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/ Backed out unused apis added in:

Jim Fulton jim at zope.com
Fri Aug 27 17:01:07 EDT 2004


Log message for revision 27309:
  Backed out unused apis added in:
  
    ------------------------------------------------------------------------
    r27269 | jim | 2004-08-25 15:29:34 -0400 (Wed, 25 Aug 2004) | 2 lines
  
    Added an api for unegistering views and resources.
  
    ------------------------------------------------------------------------
    r27266 | jim | 2004-08-25 15:01:44 -0400 (Wed, 25 Aug 2004) | 5 lines
  
    Added apis for unregistering adapters and subscribers.
  
    This (now) is needed to support testing.
  
  
  
  


Changed:
  U   Zope3/branches/ZopeX3-3.0/src/zope/component/presentation.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/component/tests/test_presentation.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.txt


-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/component/presentation.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/component/presentation.py	2004-08-27 20:41:19 UTC (rev 27308)
+++ Zope3/branches/ZopeX3-3.0/src/zope/component/presentation.py	2004-08-27 21:01:06 UTC (rev 27309)
@@ -374,34 +374,6 @@
             ] = PresentationRegistration(layer, ifaces, providing, name,
                                          factory, info)
 
-    def unprovideAdapter(self, request_type, factory, name=u'', contexts=(), 
-                       providing=zope.interface.Interface, layer='default',
-                       info=''):
-        """Provide a presentation adapter
-
-        This is a fairly low-level interface that supports both
-        resources and views.
-
-        """
-
-        ifaces = []
-        for context in contexts:
-            if not IInterface.providedBy(context) and context is not None:
-                if not isinstance(context, (type, ClassType)):
-                    raise TypeError(context, IInterface)
-                context = zope.interface.implementedBy(context)
-
-            ifaces.append(context)
-
-        ifaces.append(request_type)
-        ifaces = tuple(ifaces)
-
-        reg = self._layers[layer]
-
-        reg.unregister(ifaces, providing, name, factory)
-
-        del self._registrations[(layer, ifaces, providing, name)]
-
     def queryResource(self, name, request, default=None,
                       providing=zope.interface.Interface):
         """Look up a named resource for a given request

Modified: Zope3/branches/ZopeX3-3.0/src/zope/component/tests/test_presentation.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/component/tests/test_presentation.py	2004-08-27 20:41:19 UTC (rev 27308)
+++ Zope3/branches/ZopeX3-3.0/src/zope/component/tests/test_presentation.py	2004-08-27 21:01:06 UTC (rev 27309)
@@ -16,7 +16,7 @@
 $Id$
 """
 import unittest
-from zope.testing.doctest import DocTestSuite
+from doctest import DocTestSuite
 from zope.component.presentation import GlobalPresentationService
 import zope.interface
 
@@ -158,55 +158,10 @@
     >>> s.provideView(IContact, 'index.html', IRequest, MyView, layer='custom')
 
     >>> c = Contact()
-
-    >>> s.queryView(c, 'index.html', request)
-
     >>> request.skin = 'custom'
 
-    >>> v = s.queryView(c, 'index.html', request)
-
-    >>> v.__class__.__name__
-    'MyView'
-    >>> v.request is request
-    True
-    >>> v.context is c
-    True
-    """
-
-def test_provideAdapter():
-    """
-    provideAdapter provides a basic interface for adding views.  It is
-    similar to the adapter-service provideAdapter, except that it
-    allows a layer to be specified:
-
-    >>> s = GlobalPresentationService()
-    >>> request = Request()
-    >>> s.provideAdapter(IRequest, MyView, 'foo', [IContact])
-
-    >>> c = Contact()
     >>> v = s.queryView(c, 'foo', request)
-    >>> v.__class__.__name__
-    'MyView'
-    >>> v.request is request
-    True
-    >>> v.context is c
-    True
 
-    We can specify a layer and we can provide a view factory directly:
-
-    >>> s.defineLayer('custom')
-    >>> s.defineSkin('custom', ['custom', 'default'])
-    >>> s.provideAdapter(IRequest, MyView, 'index.html', [IContact],
-    ...                  layer='custom')
-
-    >>> c = Contact()
-
-    >>> s.queryView(c, 'index.html', request)
-
-    >>> request.skin = 'custom'
-
-    >>> v = s.queryView(c, 'index.html', request)
-
     >>> v.__class__.__name__
     'MyView'
     >>> v.request is request
@@ -215,45 +170,7 @@
     True
     """
 
-def test_unprovideAdapter():
-    """
-    unprovideAdapter allows adapters to be unregistered
 
-    >>> s = GlobalPresentationService()
-    >>> request = Request()
-    >>> s.provideAdapter(IRequest, MyView, 'foo', [IContact])
-
-    >>> c = Contact()
-    >>> v = s.queryView(c, 'foo', request)
-    >>> v.__class__.__name__
-    'MyView'
-
-    >>> s.unprovideAdapter(IRequest, MyView, 'foo', [IContact])
-    >>> s.queryView(c, 'foo', request)
-
-    We can specify a layer and we can provide a view factory directly:
-
-    >>> s.defineLayer('custom')
-    >>> s.defineSkin('custom', ['custom', 'default'])
-    >>> s.provideAdapter(IRequest, MyView, 'index.html', [IContact],
-    ...               layer='custom')
-
-    >>> c = Contact()
-
-    >>> request.skin = 'custom'
-
-    >>> v = s.queryView(c, 'index.html', request)
-
-    >>> v.__class__.__name__
-    'MyView'
-
-    >>> s.unprovideAdapter(IRequest, MyView, 'index.html', [IContact],
-    ...                 layer='custom')
-    >>> s.queryView(c, 'index.html', request)
-
-
-    """
-
 def test_default_view_names():
     """
     >>> s = GlobalPresentationService()

Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.py	2004-08-27 20:41:19 UTC (rev 27308)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.py	2004-08-27 21:01:06 UTC (rev 27309)
@@ -250,32 +250,15 @@
 
         self.dirty()
 
-    def _unadaptTo(self, specification, object, name='', with=()):
-        key = False, tuple(with), name, specification
-        old = self.adapters.get(key)
-        if old == object:
-            del self.adapters[key]
-            self.dirty()
-        else:
-            raise ValueError("Adapter not present")
-
-
     def _subscriptionAdaptTo(self, specification, object, with=()):
+        if object is None:
+            raise TypeError, ("Unregistering subscription adapters" 
+                              " isn't implemented")
+
         key = (True, tuple(with), '', specification)
         self.adapters[key] = self.adapters.get(key, ()) + (object, )
         self.dirty()
 
-    def _subscriptionUnAdaptTo(self, specification, object, with=()):
-        key = (True, tuple(with), '', specification)
-        subscribers = self.adapters[key]
-        if object in subscribers:
-            subscribers = list(subscribers)
-            subscribers.remove(object)        
-            self.adapters[key] = tuple(subscribers)
-            self.dirty()
-        else:
-            raise ValueError("Subscriber not present")
-
     def changed(self, which=None):
         self.dirty()
 
@@ -519,7 +502,7 @@
                      ):
             setattr(self, name, getattr(lookup, name))
 
-    def _with_required(self, required):
+    def register(self, required, provided, name, value):
         if required:
             with = []
             for iface in required[1:]:
@@ -531,26 +514,13 @@
         else:
             with = ()
             required = self._null
-        return with, required
-
-    def register(self, required, provided, name, value):
         
         if not isinstance(name, basestring):
-            raise TypeError("adapter names must be a strings or unicode")
+            raise TypeError("The name provided to provideAdapter "
+                            "must be a string or unicode")
 
-        with, required = self._with_required(required)
-
         required._adaptTo(provided, value, unicode(name), with)
 
-    def unregister(self, required, provided, name, value):
-        
-        if not isinstance(name, basestring):
-            raise TypeError("adapter names must be a strings or unicode")
-
-        with, required = self._with_required(required)
-
-        required._unadaptTo(provided, value, unicode(name), with)
-
     def lookupAll(self, required, provided):
         order = len(required)
         if order == 1:
@@ -607,23 +577,17 @@
             first = byname
 
     def subscribe(self, required, provided, value):
+        if required:
+            required, with = self.get(required[0]), tuple(required[1:])
+        else:
+            required = self._null
+            with = ()
 
-        with, required = self._with_required(required)
-
         if provided is None:
             provided = Null
             
         required._subscriptionAdaptTo(provided, value, with)
 
-    def unsubscribe(self, required, provided, value):
-
-        with, required = self._with_required(required)
-
-        if provided is None:
-            provided = Null
-            
-        required._subscriptionUnAdaptTo(provided, value, with)
-
 def mextends(with, rwith):
     if len(with) == len(rwith):
         for w, r in zip(with, rwith):

Modified: Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.txt
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.txt	2004-08-27 20:41:19 UTC (rev 27308)
+++ Zope3/branches/ZopeX3-3.0/src/zope/interface/adapter.txt	2004-08-27 21:01:06 UTC (rev 27309)
@@ -223,29 +223,16 @@
 Unregistering
 -------------
 
-You can unregister by calling unregister:
+You can unregister by registering None, rather than an object::
 
-  >>> registry.unregister([zope.interface.implementedBy(C2)], IP1, '', 'C21')
-  >>> registry.lookup([zope.interface.implementedBy(C2)], IP1, '')
-  21
-
-
-(You can also unregister by registering None, rather than an object::
-
-  >>> registry.register([zope.interface.implementedBy(C2)], IP1, '', 'C21')
-  >>> registry.lookup([zope.interface.implementedBy(C2)], IP1, '')
-  'C21'
   >>> registry.register([zope.interface.implementedBy(C2)], IP1, '', None)
   >>> registry.lookup([zope.interface.implementedBy(C2)], IP1, '')
   21
 
-  Of course, this means that None can't be registered. This is an
-  exception to the statement, made earlier, that the registry doesn't
-  care what gets registered.
+Of course, this means that None can't be registered. This is an
+exception to the statement, made earlier, that the registry doesn't
+care what gets registered.
 
-  This way of unregistering is deprecated.
-  )
-
 Multi-adapters
 ==============
 
@@ -445,17 +432,6 @@
   ['sub2']
 
 
-Unsubscribing
-=============
-
-You can unsubscribe subscribers:
-
-  >>> registry.unsubscribe([IR1], IP2, 'sub12 1')
-  >>> subs = registry.subscriptions([IR2], IP2)
-  >>> subs.sort()
-  >>> subs
-  ['sub12 2', 'sub22']
-
 Subscription adapters
 ---------------------
 



More information about the Zope3-Checkins mailing list