def _decorator(cls): missing = object() for interface in interfaces: classImplements(cls, interface) for name in interface: if getattr(cls, name, missing) is missing: setattr(cls, name, Passthrough(name, context)) return cls
def _delegates_advice(cls): """Add a Passthrough class for each missing interface attribute. This function connects the decorator class to the delegate class. Only new-style classes are supported. """ interface_spec, contextvar = cls.__dict__['__delegates_advice_data__'] del cls.__delegates_advice_data__ if isinstance(cls, ClassType): raise TypeError('Cannot use delegates() on a classic class: %s.' % cls) if IInterface.providedBy(interface_spec): interfaces = [interface_spec] else: interfaces = interface_spec not_found = object() for interface in interfaces: classImplements(cls, interface) for name in interface: if getattr(cls, name, not_found) is not_found: setattr(cls, name, Passthrough(name, contextvar)) return cls