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
评论列表
文章目录