def _testListenerAddGetRemove(self, testClass, eventClass, listenerClass, c=None): # Create a component for testing if c is None: c = testClass() # mockListener1 = mox.CreateMock(listenerClass) # mockListener2 = mox.CreateMock(listenerClass) mockListener1 = listenerClass() mockListener2 = listenerClass() # Verify we start from no listeners self.verifyListeners(c, eventClass) # Add one listener and verify self.addListener(c, mockListener1, listenerClass) self.verifyListeners(c, eventClass, mockListener1) # Add another listener and verify self.addListener(c, mockListener2, listenerClass) self.verifyListeners(c, eventClass, mockListener1, mockListener2) # Ensure we can fetch using parent class also if getSuperClass(eventClass) != object: self.verifyListeners(c, getSuperClass(eventClass), mockListener1, mockListener2) # Remove the first and verify self.removeListener(c, mockListener1, listenerClass) self.verifyListeners(c, eventClass, mockListener2) # Remove the remaining and verify self.removeListener(c, mockListener2, listenerClass) self.verifyListeners(c, eventClass)
def getTag(self, paintable): class1 = self._widgetMappingCache.get(paintable.__class__) if class1 is None: # Client widget annotation is searched from component hierarchy # to detect the component that presumably has client side # implementation. The server side name is used in the # transportation, but encoded into integer strings to optimized # transferred data. class1 = paintable.__class__ while not self.hasClientWidgetMapping(class1): superclass = getSuperClass(class1) if superclass is not None and issubclass(class1, IPaintable): class1 = superclass else: logger.warning(('No superclass of ' + clsname(paintable.__class__) + ' has a @ClientWidget annotation. Component ' 'will not be mapped correctly on client side.')) break self._widgetMappingCache[paintable.__class__] = class1 self._usedPaintableTypes.append(class1) return self._manager.getTagForType(class1)
def getTag(self, paintable): class1 = self._widgetMappingCache.get(paintable.__class__) if class1 is None: # Client widget annotation is searched from component hierarchy # to detect the component that presumably has client side # implementation. The server side name is used in the # transportation, but encoded into integer strings to optimized # transferred data. class1 = paintable.__class__ while not self.hasClientWidgetMapping(class1): superclass = getSuperClass(class1) if superclass is not None and issubclass(class1, IPaintable): class1 = superclass else: logger.warning( ('No superclass of ' + clsname(paintable.__class__) + ' has a @ClientWidget annotation. Component ' 'will not be mapped correctly on client side.')) break self._widgetMappingCache[paintable.__class__] = class1 self._usedPaintableTypes.append(class1) return self._manager.getTagForType(class1)
def findHighestMethod(cls, klass, method, paramTypes): ifaces = klass.getInterfaces() for i in range(len(ifaces)): ifaceMethod = cls.findHighestMethod(ifaces[i], method, paramTypes) if ifaceMethod is not None: return ifaceMethod if getSuperClass(klass) is not None: parentMethod = cls.findHighestMethod(getSuperClass(klass), method, paramTypes) if parentMethod is not None: return parentMethod methods = klass.getMethods() for i in range(len(methods)): # we ignore parameter types for now - you need to add this if methods[i].getName() == method: return methods[i] return None