[Subversion] / PEAK / src / peak / binding / components.py  

Diff of /PEAK/src/peak/binding/components.py

Parent Directory | Revision Log

version 469, Sat Jul 13 21:02:40 2002 UTC version 471, Sun Jul 14 21:28:58 2002 UTC
Line 1 
Line 1 
 """Basic binding tools"""  """Basic binding tools"""
   
   from __future__ import generators
 from once import Once, New, WeakBinding  from once import Once, New, WeakBinding
 import meta, modules  import meta, modules
   
Line 17 
Line 18 
     'Component','AutoCreated','Provider','CachingProvider',      'Component','AutoCreated','Provider','CachingProvider',
     'bindTo', 'requireBinding', 'bindToNames', 'bindToParent', 'bindToSelf',      'bindTo', 'requireBinding', 'bindToNames', 'bindToParent', 'bindToSelf',
     'getRootComponent', 'getParentComponent', 'lookupComponent',      'getRootComponent', 'getParentComponent', 'lookupComponent',
     'acquireComponent', 'globalLookup'      'acquireComponent', 'globalLookup', 'findUtility', 'findUtilities'
 ]  ]
   
   
Line 38 
Line 39 
   
   
   
   
 def Provider(callable):  def Provider(callable):
     return lambda foundIn, forObj: callable(forObj)      return lambda foundIn, forObj: callable(forObj)
   
Line 107 
Line 107 
   
 def globalLookup(name, component=None):  def globalLookup(name, component=None):
   
     """Lookup 'name' in global 'InitialContext', w/'component' in environ"""      """Lookup 'name' in global 'InitialContext', relative to 'component'"""
   
     from peak.naming.api import InitialContext      from peak.naming.api import InitialContext
   
     return InitialContext(RELATIVE_TO_COMPONENT=component).lookup(name)      return InitialContext(component).lookup(name)
   
   
   
Line 162 
Line 162 
   
   
   
   def findUtilities(component, iface, forObj=None):
   
       if forObj is None:
           forObj = component
   
       last = component
   
       while component is not None:
   
           utility = component._getUtility(iface, forObj)
   
           if utility is not None:
               yield utility
   
           last      = component
           component = component.getParentComponent()
   
   
       cfg = config.getLocal(last)
   
       if cfg is not None:
           for u in findUtilities(cfg, iface, forObj):
               yield u
   
   
   def findUtility(component, iface, forObj=None):
   
       for u in findUtilities(component, iface, forObj):
           return u
   
   
   
   
   
   
   
   
   
   
   
   
 ComponentNameSyntax = Syntax(  ComponentNameSyntax = Syntax(
     direction = 1,      direction = 1,
     separator = '/',      separator = '/',
Line 211 
Line 252 
     Interface object.  Strings and 'CompoundName' names will be interpreted      Interface object.  Strings and 'CompoundName' names will be interpreted
     as paths relative to the starting component.  An empty name will return      as paths relative to the starting component.  An empty name will return
     the starting component.  Interfaces will be lookedup using      the starting component.  Interfaces will be lookedup using
     'component.acquireUtility()'.  All other kinds of names, including URL      'findUtility(component,...)'.  All other kinds of names, including URL
     strings and 'CompositeName' instances, will be looked up using      strings and 'CompositeName' instances, will be looked up using
     'binding.globalLookup()'.      'binding.globalLookup()'.
   
Line 238 
Line 279 
         path segment."""          path segment."""
   
     if isinstance(name, InterfaceClass):      if isinstance(name, InterfaceClass):
         utility = component.acquireUtility(name)          utility = findUtility(component, name)
         if utility is None:          if utility is None:
             raise NameNotFoundException(name, resolvedObj = component)              raise NameNotFoundException(name, resolvedObj = component)
   
Line 531 
Line 572 
   
   
   
     def acquireUtility(self, iface, forObj=None, localLookup=True):      def _getUtility(self, iface, forObj):
   
         if forObj is None:  
             forObj=self  
   
         if localLookup:  
   
             provider = self.__instance_provides__.get(iface)              provider = self.__instance_provides__.get(iface)
   
Line 552 
Line 588 
                 if utility is not NOT_FOUND:                  if utility is not NOT_FOUND:
                     return utility                      return utility
   
         parent = self.getParentComponent()  
   
         if parent is None:  
             parent = config.getLocal(self)  
   
         return parent.acquireUtility(iface,forObj)  
   
   
     def registerProvider(self, ifaces, provider):      def registerProvider(self, ifaces, provider):
Line 572 
Line 602 
   
   
   
   
   
   
   
   
   
   
   
   
   
   
 class AutoCreatable(type):  class AutoCreatable(type):
   
     """Metaclass for components which auto-create when used"""      """Metaclass for components which auto-create when used"""


Generate output suitable for use with a patch program
Legend:
Removed from v.469  
changed lines
  Added in v.471

cvs-admin@eby-sarna.com

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help