def __getattr__(self, attr): if attr.startswith('_'): raise AttributeError elif attr in self: return self[attr] else: raise errors.MissingPluginError(attr)
def installPrehook(self, apiMethod, hookFunction): """ Installs a hook that will be called before the given apiMethod is called. @param apiMethod: api call to add the hook to. This should be a reference to the api object accessible from this handle. @param hookFunction: a function that will be called before apiMethod. The function must take the same parameters as apiMethod. It may modify the parameters passed on to the underlying api method, although they should also be valid. The parameters may be changed by modifying the arguments passed into the hook directly, or by returning the arguments to be passed to the api method as a list consisting of a list of arguments, and a dictionary of keywords. """ pluginName = apiMethod.im_class.__name__ methodName = apiMethod.im_func.__name__ try: plugin = self[pluginName] except KeyError: raise errors.MissingPluginError(pluginName) # W0212: Access to a protected member _installPrehook. Since # we're calling into plugin, whose public methods are api calls, # we need to do this here. #pylint: disable-msg=W0212 plugin._installPrehook(methodName, hookFunction)
def installPosthook(self, apiMethod, hookFunction): """ Installs a hook that will be called after the given apiMethod is called. @param apiMethod: api call to add the hook to. This should be a reference to the api object accessible from this handle. @param hookFunction: a function that will be called after apiMethod. The function must take the same parameters as apiMethod, except that it must take a leading argument of the current return value, and must return the new return value. It may modify the return value, and may raise an exception, though this is generally discouraged. """ pluginName = apiMethod.im_class.__name__ methodName = apiMethod.im_func.__name__ try: plugin = self[pluginName] except KeyError: raise errors.MissingPluginError(pluginName) # W0212: Access to a protected member _installPosthook. Since # we're calling into plugin, whose public methods are api calls, # we need to do this here. #pylint: disable-msg=W0212 plugin._installPosthook(methodName, hookFunction)