def assign_user_policies(user, *policies_roles):
    """Assign a sequence of policies to a user (or the anonymous user is
    ``user`` is ``None``).  (Also installed as ``assign_policies``
    method on ``User`` model.

    """
    clear_user_policies(user)
    pset = PermissionSet.objects.by_policies_and_roles(policies_roles)
    pset.refresh()
    if user is None:
        pset.anonymous_user = True
    else:
        pset.users.add(user)
    pset.save()
    cache.set(user_cache_key(user), None)