recipe-81535.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:code 作者: ActiveState 项目源码 文件源码
def __getattr__( self, attrName ):
      # Look for a cached reference to the attribute and if it isn't there,
      # fetch it from the wrapped object.
      notThere = 'Not there'
      returnAttr = self._cache.get( attrName, notThere )
      if returnAttr is notThere:
         attr = getattr( self._wrappedObject, attrName, notThere )
         if attr is notThere:
            # The attribute is missing - let it raise an AttributeError.
            getattr( self._wrappedObject, attrName )

         # We only wrap C functions, which have the type BuiltinMethodType.
         elif isinstance( attr, types.BuiltinMethodType ):
            # Base the fictitious filename on the module name or class name.
            if isinstance( self._wrappedObject, types.ModuleType ):
               objectName = self._wrappedObject.__name__
            else:
               objectName = type( self._wrappedObject ).__name__
            returnAttr = _ProfileWrapFunction( attr, objectName )
            self._cache[ attrName ] = returnAttr

         # All non-C-function attributes get returned directly.
         else:
            returnAttr = attr

      return returnAttr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号