def ensure_state(default_getter, exc_class, default_msg=None):
    """Create a decorator factory function."""
    def decorator(getter=default_getter, msg=default_msg):
        def ensure_decorator(f):
            @wraps(f)
            def inner(self, *args, **kwargs):
                if not getter(self):
                    raise exc_class(msg) if msg else exc_class()
                return f(self, *args, **kwargs)
            return inner
        return ensure_decorator
    return decorator
def ensure_state ( default_getter , exc_class , default_msg = None ) : def decorator ( getter = default_getter , msg = default_msg ) : def ensure_decorator ( f ) : @ wraps ( f ) def inner ( self , * args , ** kwargs ) : if not getter ( self ) : raise exc_class ( msg ) if msg else exc_class ( ) return f ( self , * args , ** kwargs ) return inner return ensure_decorator return decorator
Create a decorator factory function.