def clear_user_policies(user):
if user is None:<EOL><INDENT>try:<EOL><INDENT>pset = PermissionSet.objects.get(anonymous_user=True)<EOL>pset.anonymous_user = False<EOL>pset.save()<EOL><DEDENT>except ObjectDoesNotExist:<EOL><INDENT>return<EOL><DEDENT><DEDENT>else:<EOL><INDENT>pset = user.permissionset.first()<EOL><DEDENT>if pset:<EOL><INDENT>pset.refresh()<EOL>if user is not None:<EOL><INDENT>pset.users.remove(user)<EOL><DEDENT>if pset.users.count() == <NUM_LIT:0> and not pset.anonymous_user:<EOL><INDENT>pset.delete()<EOL><DEDENT><DEDENT>
Remove all policies assigned to a user (or the anonymous user if
    ``user`` is ``None``).