def perm_or_factory(perm, *args, **kwargs):
    """Check if perm is a factory (callable) and if so, apply arguments. If not, just return the perm."""
    if callable(perm):
        return perm(*args, **kwargs)
    return perm