def fixClassImplements(klass): """Switch class from __implements__ to zope implementation. This does the opposite of backwardsCompatImplements, takes a class using __implements__ and makes zope.interface know about it. Rather than using this yourself, it's better to port your code to the new API. """ if _fixedClasses.has_key(klass): return if not hasattr(klass, "__implements__"): return if isinstance(klass.__implements__, _implementsTuple): # apparently inhereted from superclass that had backwardsCompatImplements() # called on it. if subclass did its own __implements__, this would # be a regular tuple, and thus trigger the warning-enabled code branch # below, but since it's not, they're probably using new style implements() # or didn't change implements from base class at all. backwardsCompatImplements(klass) return if isinstance(klass.__implements__, (tuple, MetaInterface)): warnings.warn("Please use implements(), not __implements__ for class %s" % klass, ComponentsDeprecationWarning, stacklevel=3) iList = tupleTreeToList(klass.__implements__) if iList: declarations.classImplementsOnly(klass, *iList) _fixedClasses[klass] = 1
def fixClassImplements(klass): """Switch class from __implements__ to zope implementation. This does the opposite of backwardsCompatImplements, takes a class using __implements__ and makes zope.interface know about it. Rather than using this yourself, it's better to port your code to the new API. """ if _fixedClasses.has_key(klass): return if not hasattr(klass, "__implements__"): return if isinstance(klass.__implements__, _implementsTuple): backwardsCompatImplements(klass) return if isinstance(klass.__implements__, (tuple, MetaInterface)): warnings.warn("Please use implements(), not __implements__ for class %s" % klass, ComponentsDeprecationWarning, stacklevel=3) iList = tupleTreeToList(klass.__implements__) if iList: declarations.classImplementsOnly(klass, *iList) _fixedClasses[klass] = 1