import decorator class IdDecorator(decorator.Decorator): """A decorator that adds a field giving the object behind the wrapper.""" __slots__ = ["object"] def __init__(self, wrapper, info): super(IdDecorator, self).__init__(wrapper, info) try: # Try to get the direct object reference self.object = info.object except AttributeError: # There's not too much overhead if it's not # available. self.fail(IdDecorator) @classmethod def picklable(cls): return False @classmethod def idempotent(cls, items): return super(IdDecorator, cls).idempotent(items) and \ hasattr(self, "object") == ("object" in items)