[Subversion] / PEAK / src / peak / config / registries.py  

Diff of /PEAK/src/peak/config/registries.py

Parent Directory | Revision Log

version 1573, Sun Dec 28 00:14:24 2003 UTC version 1574, Sun Dec 28 03:52:01 2003 UTC
Line 1 
Line 1 
 from __future__ import generators  from __future__ import generators
 from peak.api import *  from peak.api import *
 from interfaces import *  from interfaces import *
 from peak.util.EigenData import EigenDict  
 from peak.util.imports import whenImported  from peak.util.imports import whenImported
 from protocols.advice import getMRO  from protocols.advice import getMRO
 from types import ClassType  from types import ClassType
   
 __all__ = [  __all__ = [
     'EigenRegistry', 'MultiKey', 'UnionOf', 'ProviderOf', 'FactoryFor',      'MultiKey', 'UnionOf', 'ProviderOf', 'FactoryFor',
 ]  ]
   
   
Line 39 
Line 38 
   
   
   
   
 class Wrapper(object):  class Wrapper(object):
   
     __slots__ = 'subject','protocol'      __slots__ = 'subject','protocol'
Line 244 
Line 244 
 )  )
   
   
 class EigenRegistry(EigenDict):  class ImmutableConfig(object):
   
     """EigenDict that takes IConfigKey objects as keys, handling inheritance"""      def __init__(self, baseMaps=(), items=()):
   
     def __init__(self):          self.depth = depths = {}
         self.depth = {}          self.keysIndex = keysIndex = {}
         self.keysIndex = {}          self.data = data = {}
         super(EigenRegistry,self).__init__()  
           for base in baseMaps:
               adapt(base,ImmutableConfig)
               for key, depth in base.depth.items():
                   old = depths.get(key,depth)
                   if old>=depth:
                       data[key] = base.data[key]
                       depths[key] = depth
   
     def lookup(self, configKey, failobj=None):              for ns,keysMap in base.keysIndex.items():
         sc = self._setCell                  keysIndex.setdefault(ns,{}).update(keysMap)
         for key in configKey.lookupKeys():  
             cell = sc(key)          for configKey,value in items:
             if cell.exists():  
                 return cell.get()  
         else:  
             return failobj  
   
     def register(self, configKey, item, depth=0):  
         """Register 'item' under 'configKey'"""  
         for key,depth in adapt(configKey,IConfigKey).registrationKeys():          for key,depth in adapt(configKey,IConfigKey).registrationKeys():
             if self.depth.get(key,depth)>=depth:  
                 self[key]=item                  if depths.get(key,depth)>=depth:
                 self.depth[key] = depth  
             key = adapt(key, IConfigKey)                      ckey = adapt(key, IConfigKey)
             for k in key.parentKeys():  
                 self.keysIndex.setdefault(k,{})[key] = True                      for k in ckey.parentKeys():
                           keysIndex.setdefault(k,{})[ckey] = True
   
                       data[key]=value
                       depths[key] = depth
   
   
   
   
   
   
   
   
   
       def lookup(self, configKey, failObj=None):
           data = self.data
           for key in configKey.lookupKeys():
               if key in data:
                   return data[key]
           return failObj
   
   
     def _configKeysMatching(self, configKey):      def _configKeysMatching(self, configKey):
   
         index = self.keysIndex          index = self.keysIndex
   
         if not index:          if not index:
Line 285 
Line 306 
   
   
   
     def update(self,other):  
         """Conservatively merge in another EigenRegistry"""  
   
         if not isinstance(other,EigenRegistry):  
             raise TypeError("Not an EigenRegistry", other)  
   
         mydepth = self.depth  
         get = mydepth.get  
         sc = self._setCell  
         for iface, depth in other.depth.items():  
             old = get(iface,depth)  
             if old>=depth:  
                 sc(iface).set(other[iface])  
                 mydepth[iface] = depth  
   
         for k,v in other.keysIndex.items():  
             self.keysIndex.setdefault(k,{}).update(v)  
   
   
     def setdefault(self,key,failobj=None):  
         raise NotImplementedError  
   
     def __delitem__(self,key):  
         raise NotImplementedError  
   
     def clear(self):  
         raise NotImplementedError  
   
   
   


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

cvs-admin@eby-sarna.com

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help