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

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

Parent Directory | Revision Log

version 1847, Mon Oct 11 19:36:04 2004 UTC version 1848, Mon Oct 11 21:38:07 2004 UTC
Line 559 
Line 559 
     names beginning with an '_', and traversing to the name 'get' will give you      names beginning with an '_', and traversing to the name 'get' will give you
     the namespace's 'get' method, not the 'get' property in the namespace.  To      the namespace's 'get' method, not the 'get' property in the namespace.  To
     obtain the 'get' property, or properties beginning with '_', you must use      obtain the 'get' property, or properties beginning with '_', you must use
     the mapping style of access, as shown above."""      the mapping style of access, as shown above.
   
     def __init__(self, prefix, target=NOT_GIVEN, cacheAttrs=True):      NOTE: By default, 'Namespace' instances cache every key that's looked up in
       them.  If you are holding a reference to a namespace, and you expect an
       unbounded number of potential lookups, do not want references held to the
       results, or are looking up dynamically changing or dynamically created
       properties, you should disable caching via the 'cache=False' keyword arg."""
   
       def __init__(self, prefix, target=NOT_GIVEN, cache=True):
         self._prefix = PropertyName(prefix).asPrefix()          self._prefix = PropertyName(prefix).asPrefix()
         self._target = target          self._target = target
         self._cache = cacheAttrs          self._cache = cache; self._data = {}
   
     def __call__(self, suffix):      def __call__(self, suffix):
         """Return a sub-namespace for 'suffix'"""          """Return a sub-namespace for 'suffix'"""
Line 576 
Line 582 
         if not attr.startswith('_'):          if not attr.startswith('_'):
             ob = self.get(attr, NOT_FOUND)              ob = self.get(attr, NOT_FOUND)
             if ob is not NOT_FOUND:              if ob is not NOT_FOUND:
                 if self._cache:                  if self._cache and not hasattr(self.__class__,attr):
                     setattr(self,attr,ob)   # Cache for future use                      setattr(self,attr,ob)   # Cache for future use
                 return ob                  return ob
         raise AttributeError,attr          raise AttributeError,attr
Line 592 
Line 598 
   
     def get(self,key,default=None):      def get(self,key,default=None):
         """Return property 'key' within this namespace, or 'default'"""          """Return property 'key' within this namespace, or 'default'"""
   
         if self._target is not NOT_GIVEN:          if self._target is not NOT_GIVEN:
             return lookup(              if key in self._data:
                   return self._data[key]
   
               result = lookup(
                 self._target,PropertyName.fromString(self._prefix+key),default                  self._target,PropertyName.fromString(self._prefix+key),default
             )              )
               if self._cache and result is not default:
                   self._data[key] = result
               return result
   
         return default          return default
   
   
Line 603 
Line 617 
         return "config.Namespace(%r,%r)" % (self._prefix,self._target)          return "config.Namespace(%r,%r)" % (self._prefix,self._target)
   
   
   
   
   
   
   
   
   
   
   
   
     def keys(self):      def keys(self):
   
         items = []          items = []
Line 650 
Line 654 
   
   
   
   
   
   
   
 class __NamespaceExtensions(protocols.Adapter):  class __NamespaceExtensions(protocols.Adapter):
   
     protocols.advise(      protocols.advise(


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

cvs-admin@eby-sarna.com

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help