human
Complete the below
def check_instance_state(vm_state=None, task_state=(None,)):

    ''''Decorator to check VM and/or task state before entry to API functions.
    If the instance is in the wrong state, the wrapper will raise an exception.'
    '''
assistant
#Here is the Python code you requested.
    if ((vm_state is not None) and (not isinstance(vm_state, set))):
        vm_state = set(vm_state)
    if ((task_state is not None) and (not isinstance(task_state, set))):
        task_state = set(task_state)
    def outer(f):
        @functools.wraps(f)
        def inner(self, context, instance, *args, **kw):
            if ((vm_state is not None) and (instance['vm_state'] not in vm_state)):
                raise exception.InstanceInvalidState(attr='vm_state', instance_uuid=instance['uuid'], state=instance['vm_state'], method=f.__name__)
            if ((task_state is not None) and (instance['task_state'] not in task_state)):
                raise exception.InstanceInvalidState(attr='task_state', instance_uuid=instance['uuid'], state=instance['task_state'], method=f.__name__)
            return f(self, context, instance, *args, **kw)
        return inner
    return outer