def getAdapterFactory(self, fromInterface, toInterface, default): """Return registered adapter for a given class and interface. """ R = self.adapterRegistry.get((fromInterface, toInterface), None) if R is None: adapterQual = self.adapterRegistry.get((qual(fromInterface), qual(toInterface)), None) if adapterQual is None: return default R = namedAny(adapterQual) R.__implements__ = tupleTreeToList(getattr(R, '__implements__', ())) self.adapterRegistry[(fromInterface, toInterface)] = R return R
def getAdapterFactory(self, fromInterface, toInterface, default): """Return registered adapter for a given class and interface. """ R = self.adapterRegistry.get((fromInterface, toInterface), None) if R is None: adapterQual = self.adapterRegistry.get( (qual(fromInterface), qual(toInterface)), None) if adapterQual is None: return default R = namedAny(adapterQual) R.__implements__ = tupleTreeToList(getattr(R, '__implements__', ())) self.adapterRegistry[(fromInterface, toInterface)] = R return R
def removeComponent(self, component): """ Remove the given component from me entirely, for all interfaces for which it has been registered. @return: a list of the interfaces that were removed. """ if (isinstance(component, types.ClassType) or isinstance(component, types.TypeType)): warnings.warn("passing interface to removeComponent, you probably want unsetComponent", DeprecationWarning, 1) self.unsetComponent(component) return [component] l = [] for k, v in self._adapterCache.items(): if v is component: del self._adapterCache[k] l.append(namedAny(k)) return l
def removeComponent(self, component): """ Remove the given component from me entirely, for all interfaces for which it has been registered. @return: a list of the interfaces that were removed. """ if (isinstance(component, types.ClassType) or isinstance(component, types.TypeType)): warnings.warn( "passing interface to removeComponent, you probably want unsetComponent", DeprecationWarning, 1) self.unsetComponent(component) return [component] l = [] for k, v in self._adapterCache.items(): if v is component: del self._adapterCache[k] l.append(namedAny(k)) return l
def getFlattener(original): """Get a flattener function with signature (ctx, original) for the object original. """ if hasattr(original, '__class__'): klas = original.__class__ else: klas = type(original) fromInterfaces = compy.getInterfaces(klas) + [klas] for inter in fromInterfaces: adapter = _flatteners.get(inter, None) if adapter is not None: return adapter interQual = util.qual(inter) adapterQual = _lazy_flatteners.get(interQual, None) if adapterQual is not None: adapter = util.namedAny(adapterQual) registerFlattener(adapter, inter) del _lazy_flatteners[interQual] return adapter print "***", fromInterfaces
def getFlattener(original): """Get a flattener function with signature (ctx, original) for the object original. """ if hasattr(original, '__class__'): klas = original.__class__ else: klas = type(original) fromInterfaces = compy.getInterfaces(klas) + [klas] for inter in fromInterfaces: adapter = _flatteners.get(inter, None) if adapter is not None: return adapter interQual = util.qual(inter) adapterQual = _lazy_flatteners.get(interQual, None) if adapterQual is not None: adapter = util.namedAny(adapterQual) registerFlattener(adapter, inter) #for fromInter in fromInterfaces: # registerFlattener(adapter, fromInter) del _lazy_flatteners[interQual] return adapter print "***", fromInterfaces