A descriptor modifier which allows __set__ to be called at most once.

def setonce(decorator):
    """A descriptor modifier which allows __set__ to be called at most once."""
    def decorate(fn, *args, **kwargs):
        parent = decorator(fn, *args, **kwargs)
        #doc = _add_msg(getattr(parent, '__doc__', None), '*@setonce*')
        doc = getattr(parent, '__doc__', None)
        assert hasattr(parent, "__set__") # don't use for non-data descriptors!
        return _setonce(fn.__name__, parent, doc)
    return decorate