def assign_user_policies(user, *policies_roles):
clear_user_policies(user)<EOL>pset = PermissionSet.objects.by_policies_and_roles(policies_roles)<EOL>pset.refresh()<EOL>if user is None:<EOL><INDENT>pset.anonymous_user = True<EOL><DEDENT>else:<EOL><INDENT>pset.users.add(user)<EOL><DEDENT>pset.save()<EOL>cache.set(user_cache_key(user), None)<EOL>
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.