[Zope-Checkins] CVS: Packages/ComponentArchitecture - NameProvider.py:1.1.2.1 FactoryComponents.py:1.1.2.3 InputToName.py:1.1.2.3 InterfaceComponents.py:1.1.2.4 Presentation.py:1.1.2.7 __init__.py:1.1.2.7
Shane Hathaway
shane@digicool.com
Fri, 3 Aug 2001 00:55:23 -0400
Update of /cvs-repository/Packages/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv10905
Modified Files:
Tag: NR-branch
FactoryComponents.py InputToName.py InterfaceComponents.py
Presentation.py __init__.py
Added Files:
Tag: NR-branch
NameProvider.py
Log Message:
Created NameProvider component classification and interfaces, then converted
InterfaceComponents to use it. Used the term "component realization",
which makes sense at this level of abstraction, I hope.
=== Added File Packages/ComponentArchitecture/NameProvider.py ===
=== Packages/ComponentArchitecture/FactoryComponents.py 1.1.2.2 => 1.1.2.3 ===
import Interface
from InputToName import InputToNameService, InputToNameComponent, \
- GlobalInputToNameRegistry, getBinder, listComponentNames
+ GlobalInputToNameRegistry, getRealization, listComponentNames
FACTORY_SERVICE_NAME = 'factories'
@@ -113,13 +113,13 @@
Finds a factory for children of an object by examining what the
parent implements. Searches in services then the global registry.
'''
- b = getBinder(FACTORY_SERVICE_NAME, global_reg, object, name)
- if b is None:
+ r = getRealization(FACTORY_SERVICE_NAME, global_reg, object, name)
+ if r is None:
if default is not _marker:
return default
else:
raise Errors.FactoryNotFound(object, name)
- return b(object)
+ return r(object)
def listFactoryNames(object, inputs=None):
return listComponentNames(FACTORY_SERVICE_NAME, global_reg,
=== Packages/ComponentArchitecture/InputToName.py 1.1.2.2 => 1.1.2.3 ===
+'''
+Common interfaces and utilities for components that require an interface
+and provide a name.
+'''
+
from types import ListType
from Acquisition import aq_acquire
@@ -11,11 +16,9 @@
class InputToNameService (Service):
'''
'''
-
- def getComponentBinder(inputs, name):
+ def getRealization(inputs, name):
'''
- Returns an object which, when called with content as the only
- argument, returns the component bound to content.
+ Returns a realization of the located component.
'''
def listComponentNames(inputs):
@@ -27,9 +30,9 @@
class InputToNameContainer (Interface.Base):
'''
'''
- def getBinder(input, name):
+ def getRealizationForInput(input, name):
'''
- Returns a component binder. Returns None if not found.
+ Returns a realization of a component. Returns None if not found.
Note that this method is passed only one input. It should
not look at input.__bases__.
'''
@@ -60,50 +63,51 @@
class GlobalInputToNameRegistry:
def __init__(self):
- self._binders = {}
+ self._comprlz = {} # {(input, name) -> realization}
- def provideBinder(self, input, name, b):
+ def provideRealization(self, input, name, r):
'''
- Registers a binder.
+ Registers a realization of a component.
'''
- self._binders[(input, name)] = b
+ self._comprlz[(input, name)] = r
- def _getBinder(self, input, name):
+ def _getRealization(self, input, name):
'''
- Finds a registered binder given an interface and a name.
+ Finds a registered component realization given an interface
+ and a name.
'''
- b = self._comps.get((input, name), None)
- if b is not None:
- return b
+ r = self._comprlz.get((input, name), None)
+ if r is not None:
+ return r
bases = getattr(input, '__bases__', ())
if bases:
for base in bases:
- b = self._getBinder(base, name)
- if b is not None:
- return b
+ r = self._getRealization(base, name)
+ if r is not None:
+ return r
return None
- def _getBinderForInterfaces(self, inputs, name):
+ def _getRealizationForInterfaces(self, inputs, name):
'''
Finds a registered binder given a hierarchy of input interfaces
and a name.
'''
if type(inputs) is TupleType:
for input in inputs:
- b = self._getBinderForInterfaces(input, name)
- if b is not None:
- return b
+ r = self._getRealizationForInterfaces(input, name)
+ if r is not None:
+ return r
else:
# inputs is an interface object.
- return self._getBinder(inputs, name)
+ return self._getRealization(inputs, name)
- def getComponentBinder(self, inputs, name):
+ def getRealization(self, inputs, name):
if inputs:
- b = self._getBinderForInterfaces(inputs, name)
+ r = self._getRealizationForInterfaces(inputs, name)
else:
# No input interfaces known.
- b = self._getBinder(None, name)
- return c
+ r = self._getRealization(None, name)
+ return r
def listComponentNames(self, inputs):
'''
@@ -112,27 +116,27 @@
'''
# inputs is assumed to be a flat list.
res = []
- for base_input, name in self._binders.keys():
+ for base_input, name in self._comprlz.keys():
for i in inputs:
if i == base_input or i.extends(base_input):
res.append(name)
return res
-def _findBinder(x_orig, x_ob, x_name, sm, (service_name,
+def _findRealization(x_orig, x_ob, x_name, sm, (service_name,
inputs, name, result)):
'''
This is an acquisition filter callback.
'''
s = sm.getService(service_name, None)
if s is not None:
- b = s.getComponentBinder(inputs, name)
- if b is not None:
- result.append(b)
+ r = s.getRealization(inputs, name)
+ if r is not None:
+ result.append(r)
return 1
return 0
-def getBinder(service_name, global_reg, object, name):
+def getRealization(service_name, global_reg, object, name):
'''
Finds a component to apply to an object by examining what it
implements. Searches in services then the global registry.
@@ -141,15 +145,15 @@
inputs = tuple(objectImplements(object))
result = []
try:
- aq_acquire(object, SERVICE_MANAGER_NAME, _findBinder,
+ aq_acquire(object, SERVICE_MANAGER_NAME, _findRealization,
(service_name, inputs, name, result), 1, None, 1)
except AttributeError:
pass
if result:
- b = result[0]
+ r = result[0]
else:
- b = global_reg.getComponentBinder(inputs, name)
- return b
+ r = global_reg.getRealization(inputs, name)
+ return r
def _listNames(x_orig, x_ob, x_name, sm, (service_name, inputs, result)):
'''
=== Packages/ComponentArchitecture/InterfaceComponents.py 1.1.2.3 => 1.1.2.4 ===
#
##############################################################################
-"""(simple) Presentation component management
+"""Interface component management
"""
-from Service import Service, SERVICE_MANAGER_NAME
-from Acquisition import aq_acquire
-from Interface import Base, objectImplements
-from types import StringType
+import Errors
+import Interface
+from NameProvider import NameProviderService, NameProviderComponent, \
+ GlobalNameRegistry, getRealization, listComponentNames
INTERFACES_SERVICE_NAME = 'interfaces'
-class InterfacesService (Service):
+class InterfacesService (NameProviderService):
'''
'''
- def listInterfaces():
- '''
- Returns a series of interfaces.
- '''
- def getLocalInterface(name):
- '''
- Returns an interface or None.
- '''
-
-
-class LocalNamedInterface (Base):
+class InterfaceComponent (NameProviderComponent):
'''
'''
-
-_marker = [] # Create a new marker.
-
-
-
-def _gatherInterfaces(x_orig, x_ob, x_name, sm, result):
+class LabelInterface (Interface.Base):
'''
- This is an acquisition filter callback.
- It calls listInterfaces() on each InterfacesService.
+ A marker interface that is identifiable purely by name.
'''
- s = sm.getService(INTERFACES_SERVICE_NAME, None)
- if s is not None:
- r = s.listInterfaces()
- if r:
- result.extend(list(r))
- return 0
-def listInterfaces(object):
- result = []
- try:
- aq_acquire(object, SERVICE_MANAGER_NAME, _gatherInterfaces,
- result, 1, None, 1)
- except AttributeError:
- pass
- return result
+global_reg = GlobalNameRegistry()
-def _findLocalInterface(x_orig, x_ob, x_name, sm, (name, result)):
- '''
- This is an acquisition filter callback.
- '''
- s = sm.getService(INTERFACES_SERVICE_NAME, None)
- if s is not None:
- i = s.getLocalInterface(name)
- if i is not None:
- result.append(i)
- return 1
- return 0
+_marker = [] # Create a new marker object.
-def getLocalInterface(object, name, default=_marker):
- result = []
- try:
- aq_acquire(object, SERVICE_MANAGER_NAME, _findLocalInterface,
- (name, result), 1, None, 1)
- except AttributeError:
- pass
- if result:
- return result[0]
- if default is _marker:
- raise Errors.InterfaceNotFound(object, name)
- else:
- return default
+def getInterface(object, name, default=_marker):
+ i = getRealization(INTERFACES_SERVICE_NAME, global_reg, object, name)
+ if i is None:
+ if default is not _marker:
+ return default
+ else:
+ raise Errors.InterfaceNotFound(object, name)
+ return i
+def listInterfaceNames(object):
+ return listComponentNames(INTERFACES_SERVICE_NAME, global_reg, object)
def flattenInterfaceList(object, interfaces, append):
# Helper for objectImplements().
@@ -174,17 +132,15 @@
append(i)
elif type(i) is StringType:
# Look up the interface.
- iface = getLocalInterface(object, i, None)
+ iface = getInterface(object, i, None)
if iface is not None:
append(iface)
else:
flattenInterfaceList(object, i, append)
-
-_realObjectImplements = objectImplements
-
def objectImplements(object):
'''
- Dereferences local named interfaces.
+ Dereferences labels.
'''
- return _realObjectImplements(object, flattenfunc=flattenInterfaceList)
+ return Interface.objectImplements(
+ object, flattenfunc=flattenInterfaceList)
=== Packages/ComponentArchitecture/Presentation.py 1.1.2.6 => 1.1.2.7 ===
import Interface
from InputToName import InputToNameService, InputToNameComponent, \
- GlobalInputToNameRegistry, getBinder
+ GlobalInputToNameRegistry, getRealization
PRESENTATION_SERVICE_NAME = 'presentation'
@@ -113,10 +113,10 @@
Finds a presentation for an object by examining what it implements.
Searches in services then the global registry.
'''
- b = getBinder(PRESENTATION_SERVICE_NAME, global_reg, object, name)
- if b is None:
+ r = getRealization(PRESENTATION_SERVICE_NAME, global_reg, object, name)
+ if r is None:
if default is not _marker:
return default
else:
raise Errors.PresentationNotFound(object, name)
- return b(object)
+ return r(object)
=== Packages/ComponentArchitecture/__init__.py 1.1.2.6 => 1.1.2.7 ===
import Presentation
getPresentation = Presentation.getPresentation
-providePresentation = Presentation.global_reg.provideBinder
+providePresentation = Presentation.global_reg.provideRealization
__all__ = (