[Zope3-checkins] SVN: Zope3/trunk/src/zope/component/ Changed XXX
to TODO.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sat Jul 10 10:45:36 EDT 2004
Log message for revision 26405:
Changed XXX to TODO.
Removed a lot of the backward-compatibility code, which got rid of
several XXX.
zope.component is now clean.
-=-
Modified: Zope3/trunk/src/zope/component/__init__.py
===================================================================
--- Zope3/trunk/src/zope/component/__init__.py 2004-07-10 14:44:16 UTC (rev 26404)
+++ Zope3/trunk/src/zope/component/__init__.py 2004-07-10 14:45:36 UTC (rev 26405)
@@ -51,38 +51,17 @@
def getGlobalService(name):
return serviceManager.getService(name)
-def getServiceManager(context):
- # Backwards compatibility stub
- warnings.warn("getServiceManager(context) is deprecated,"
- " use getServices(context=None) instead.",
- DeprecationWarning, 2)
- return getServices(context)
-
-
def getServices(context=None):
if context is None:
return serviceManager
else:
# Use the global service manager to adapt context to IServiceService
# to avoid the recursion implied by using a local getAdapter call.
+ try:
+ return IServiceService(context)
+ except TypeError, error:
+ raise ComponentLookupError(*error.args)
- # We should be using the line of code below.
- ## return IServiceService(context)
- #
- # Instead, we need to support code that has passed in an object
- # as context, at least until the whole component API is fixed up.
- # XXX try ripping this code out.
- sm = IServiceService(context, None)
- if sm is None:
- # Deprecated support for a context that isn't adaptable to
- # IServiceService. Return the default service manager.
- # warnings.warn("getServices' context arg must be None or"
- # " adaptable to IServiceService.",
- # DeprecationWarning, warningLevel())
- return serviceManager
- else:
- return sm
-
getServices = hookable(getServices)
def getService(name, context=None):
@@ -94,23 +73,9 @@
# Utility service
def getUtility(interface, name='', context=None):
- if not isinstance(name, basestring):
- context, interface, name = interface, name, context
- if name is None:
- name = ''
- warnings.warn("getUtility(context, interface, name) is deprecated."
- " Use getUtility(interface, name, context=context).",
- DeprecationWarning, warningLevel())
return getService(Utilities, context=context).getUtility(interface, name)
def queryUtility(interface, name='', default=None, context=None):
- ## XXX this check is for migration. Remove soon.
- if (not IInterface.providedBy(interface) or
- not isinstance(name, basestring) or
- isinstance(default, basestring)):
- raise TypeError("queryUtility got nonsense arguments."
- " Check that you are updated with the"
- " component API change.")
return getService(Utilities, context).queryUtility(
interface, name, default)
@@ -234,29 +199,10 @@
yield name, factory
break
-def getFactory(context, name):
- warnings.warn(
- "Use getUtility(IFactory, name, context) instead of getFactory(...)",
- DeprecationWarning, 2)
- return getUtility(IFactory, name, context=context)
-def queryFactory(context, name, default=None):
- warnings.warn(
- "Use getUtility(IFactory, name, context) instead of getFactory(...)",
- DeprecationWarning, 2)
- return queryUtility(IFactory, name=name, context=context)
-
-
# Presentation service
def getView(object, name, request, providing=Interface, context=None):
- if not IInterface.providedBy(providing):
- providing, context = context, providing
- warnings.warn("Use getView(object, name, request,"
- " providing=Interface, context=Interface)"
- " instead of getView(object, name, request,"
- " context=None, providing=Interface)",
- DeprecationWarning, 2)
view = queryView(object, name, request, context=context,
providing=providing)
if view is not None:
@@ -306,9 +252,6 @@
return s.queryDefaultViewName(object, request, default)
def getResource(name, request, providing=Interface, context=None):
- if isinstance(request, basestring):
- # "Backwards compatibility"
- raise TypeError("getResource got incorrect arguments.")
view = queryResource(name, request, providing=providing, context=context)
if view is not None:
return view
@@ -317,8 +260,5 @@
def queryResource(name, request, default=None, providing=Interface,
context=None):
- if isinstance(request, basestring):
- # "Backwards compatibility"
- raise TypeError("queryResource got incorrect arguments.")
s = getService(Presentation, context)
return s.queryResource(name, request, default, providing=providing)
Modified: Zope3/trunk/src/zope/component/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/component/interfaces.py 2004-07-10 14:44:16 UTC (rev 26404)
+++ Zope3/trunk/src/zope/component/interfaces.py 2004-07-10 14:45:36 UTC (rev 26405)
@@ -41,9 +41,6 @@
this adapter is returned.
"""
- def getServiceManager(context):
- """Backwards compatibility for getServices()"""
-
def getService(name, context=None):
"""Get a named service.
@@ -229,7 +226,8 @@
# Factory service
- # XXX: Hard to make context a keyword, leaving as it is
+ # TODO: Hard to make context a keyword, leaving as it is. Maybe we should
+ # at least move it to the second position.
def createObject(context, name, *args, **kwargs):
"""Create an object using a factory
@@ -253,24 +251,6 @@
create objects which implement the given interface.
"""
- # XXX: This method is deprecated, since factories are utiltities
- def getFactory(context, name):
- """Get a factory
-
- Get the factory of the given name that is nearest to the
- context. If a matching factory cannot be found raises
- ComponentLookupError
- """
-
- # XXX: This method is deprecated, since factories are utiltities
- def queryFactory(context, name, default=None):
- """Get a factory
-
- Get the factory of the given name that is nearest to the
- context. If a matching factory cannot be found then the
- default is returned.
- """
-
# Presentation service
def getView(object, name, request, providing=Interface, context=None):
Modified: Zope3/trunk/src/zope/component/tests/test_api.py
===================================================================
--- Zope3/trunk/src/zope/component/tests/test_api.py 2004-07-10 14:44:16 UTC (rev 26404)
+++ Zope3/trunk/src/zope/component/tests/test_api.py 2004-07-10 14:45:36 UTC (rev 26405)
@@ -124,10 +124,9 @@
context = ConformsToIServiceService(servicemanager)
self.assert_(getServices(context) is servicemanager)
- # XXX enable this test before checking in
# Using a context that is not adaptable to IServiceService should
# fail.
- ##self.assertRaises(ComponentLookupError, getServices, object())
+ self.assertRaises(ComponentLookupError, getServices, object())
def test_getService(self):
from zope.component import getService, getServices
@@ -147,11 +146,10 @@
context = ConformsToIServiceService(servicemanager)
self.assert_(getService(Adapters, context) is adapterservice)
- # XXX enable this test before checking in
# Using a context that is not adaptable to IServiceService should
# fail.
- ##self.assertRaises(ComponentLookupError,
- ## getService, Adapters, object())
+ self.assertRaises(ComponentLookupError,
+ getService, Adapters, object())
def testAdapterInContext(self):
class I1(Interface):
More information about the Zope3-Checkins
mailing list