<commit_before># vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Handles all API requests relating to instances (guest vms).
"""

import datetime
import logging
import time
import functools

from nova import db
from nova import exception
from nova import flags
from nova import quota
from nova import rpc
from nova import utils
from nova.compute import instance_types
from nova.db import base

FLAGS = flags.FLAGS


def checks_instance_lock(function):
    """
    decorator used for preventing action against locked instances
    unless, of course, you happen to be admin

    """

    @functools.wraps(function)
    def decorated_function(*args, **kwargs):

        # assume worst case (have to declare so they are in scope)
        admin = False
        locked = True

        # grab args to function
        try:
            if 'context' in kwargs:
                context = kwargs['context']
            else:
                context = args[1]
            if 'instance_id' in kwargs:
                instance_id = kwargs['instance_id']
            else:
                instance_id = args[2]
            locked = ComputeAPI().get_lock(context, instance_id)
            admin = context.is_admin
        except Excetion as e:
            logging.error(_("check_instance_lock: arguments: |%s| |%s|"), args,
                                                                        kwargs)
            raise e

        # if admin or unlocked call function, otherwise 405
        if admin or not locked:
            return function(*args, **kwargs)
        raise Exception(_("Instance is locked, cannot execute |%s|"), function)

    return decorated_function
<commit_msg>typo, trying to hurry.. look where that got me<commit_after># vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

"""
Handles all API requests relating to instances (guest vms).
"""

import datetime
import logging
import time
import functools

from nova import db
from nova import exception
from nova import flags
from nova import quota
from nova import rpc
from nova import utils
from nova.compute import instance_types
from nova.db import base

FLAGS = flags.FLAGS


def checks_instance_lock(function):
    """
    decorator used for preventing action against locked instances
    unless, of course, you happen to be admin

    """

    @functools.wraps(function)
    def decorated_function(*args, **kwargs):

        # assume worst case (have to declare so they are in scope)
        admin = False
        locked = True

        # grab args to function
        try:
            if 'context' in kwargs:
                context = kwargs['context']
            else:
                context = args[1]
            if 'instance_id' in kwargs:
                instance_id = kwargs['instance_id']
            else:
                instance_id = args[2]
            locked = ComputeAPI().get_lock(context, instance_id)
            admin = context.is_admin
        except Exception as e:
            logging.error(_("check_instance_lock: arguments: |%s| |%s|"), args,
                                                                        kwargs)
            raise e

        # if admin or unlocked call function, otherwise 405
        if admin or not locked:
            return function(*args, **kwargs)
        raise Exception(_("Instance is locked, cannot execute |%s|"), function)

    return decorated_function

{'fraction_non_alphanumeric': 0.06764584195283409, 'fraction_numerical': 0.006619776582540339, 'mean_word_length': 2.431511710432931, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7178373', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1200, 'n_words': 524}