[Zope3-checkins] CVS: Zope3/src/zope/component - __init__.py:1.10

Jim Fulton jim@zope.com
Fri, 23 May 2003 13:52:12 -0400


Update of /cvs-repository/Zope3/src/zope/component
In directory cvs.zope.org:/tmp/cvs-serv14703/src/zope/component

Modified Files:
	__init__.py 
Log Message:
Added an __all__.

Refactored the code to avoid some duplicated logic.

Made getNamedAdapter hookable.


=== Zope3/src/zope/component/__init__.py 1.9 => 1.10 ===
--- Zope3/src/zope/component/__init__.py:1.9	Wed May 21 16:30:05 2003
+++ Zope3/src/zope/component/__init__.py	Fri May 23 13:52:12 2003
@@ -34,6 +34,31 @@
 
 moduleProvides(IComponentArchitecture)
 
+__all__ = (
+    "queryServiceManager", 
+    "getServiceManager", 
+    "getService", 
+    "queryService", 
+    "getServiceDefinitions", 
+    "getUtility", 
+    "queryUtility", 
+    "getAdapter", 
+    "queryAdapter", 
+    "getNamedAdapter", 
+    "queryNamedAdapter", 
+    "createObject", 
+    "getFactory", 
+    "queryFactory", 
+    "getFactoryInterfaces", 
+    "getSkin", 
+    "getView", 
+    "queryView", 
+    "getDefaultViewName", 
+    "queryDefaultViewName", 
+    "getResource", 
+    "queryResource",
+    )
+
 def queryServiceManager(context, default=None):
     try:
         return getServiceManager(context)
@@ -68,7 +93,7 @@
 # Adapter service
 
 def getAdapter(object, interface, name='', context=None):
-    adapter = queryAdapter(object, interface, name=name, context=context)
+    adapter = queryAdapter(object, interface, None, name, context)
     if adapter is None:
         raise ComponentLookupError(object, interface)
     return adapter
@@ -103,15 +128,8 @@
     if interface.isImplementedBy(object):
         return object
 
-    if context is None:
-        context = object
-    try:
-        adapters = getService(context, Adapters)
-    except ComponentLookupError:
-        # Oh blast, no adapter service. We're probably just running from a test
-        return default
+    return queryNamedAdapter(object, interface, name, default, context)
 
-    return adapters.queryNamedAdapter(object, interface, name, default)
 
 def getNamedAdapter(object, interface, name, context=None):
     adapter = queryNamedAdapter(object, interface, name, context=context)
@@ -130,6 +148,8 @@
 
     return adapters.queryNamedAdapter(object, interface, name, default)
 
+queryNamedAdapter = hookable(queryNamedAdapter)
+
 # Factory service
 
 def createObject(context, name, *args, **kwargs):
@@ -190,4 +210,3 @@
     return getService(wrapped_object,
                       Resources).queryResource(
         wrapped_object, name, request, default)
-