def declareProvides(self,protocol,adapter=NO_ADAPTER_NEEDED,depth=1): registry = self.__dict__.get('__protocols_provided__') if registry is None: self.__protocols_provided__ = registry = {} if updateWithSimplestAdapter(registry,protocol,adapter,depth): adapt(protocol,IOpenProtocol).addImplicationListener(self) return True
def registerObject(self, ob, adapter=NO_ADAPTER_NEEDED,depth=1): # Object needs to be able to handle registration if api.adapt(ob,IOpenProvider).declareProvides(self,adapter,depth): if adapter is DOES_NOT_SUPPORT: return # non-support doesn't imply non-support of implied # Handle implied protocols for proto, (extender,d) in self.getImpliedProtocols(): api.declareAdapterForObject( proto, composeAdapters(adapter,self,extender), ob, depth+d )
def ADAPT_SEQUENCE(ob, proto): """Convert iterable 'ob' into list of objects implementing 'proto'""" marker = object() out = [] proto = proto.baseProtocol # get the protocol to adapt to for item in ob: item = adapt(item, proto, marker) if item is marker: return None # can't adapt unless all members adapt out.append(item) return out
def ADAPT_SEQUENCE ( ob, proto ): """Convert iterable 'ob' into list of objects implementing 'proto'""" marker = object() out = [ ] proto = proto.baseProtocol # get the protocol to adapt to for item in ob: item = adapt( item, proto, marker ) if item is marker: return None # can't adapt unless all members adapt out.append( item ) return out
def declareProvides(self, protocol, adapter=NO_ADAPTER_NEEDED, depth=1): if updateWithSimplestAdapter(self.reg, protocol, adapter, depth): adapt(protocol,IOpenProtocol).addImplicationListener(self.reg) return True
def __call__(self, ob, default=api._marker): """Adapt to this protocol""" return api.adapt(ob,self,default)
def __adapt__(self, obj): return adapt(self,IOpenProtocol).__adapt__(obj)
def __adapt__(self, obj): return adapt(self, IOpenProtocol).__adapt__(obj)