1 from types import ModuleType, ClassType
3 from sfa.util.faults import SfaNotImplemented, SfaAPIError
4 from sfa.util.sfalogging import logger
9 This class acts as a wrapper around an SFA interface manager module, but
10 can be used with any python module. The purpose of this class is raise a
11 SfaNotImplemented exception if someone attempts to use an attribute
12 (could be a callable) thats not available in the library by checking the
13 library using hasattr. This helps to communicate better errors messages
14 to the users and developers in the event that a specifiec operation
15 is not implemented by a libarary and will generally be more helpful than
16 the standard AttributeError
18 def __init__(self, manager, interface, config):
19 if isinstance (manager, ModuleType):
20 # old-fashioned module implementation
21 self.manager = manager
22 elif isinstance (manager, ClassType):
23 # create an instance; we don't pass the api in argument as it is passed
24 # to the actual method calls anyway
25 self.manager = manager(config)
27 raise SfaAPIError,"Argument to ManagerWrapper must be a module or class"
28 self.interface = interface
30 def __getattr__(self, method):
31 if not hasattr(self.manager, method):
32 raise SfaNotImplemented(self.interface, method)
33 return getattr(self.manager, method)