<commit_before># Copyright (c) 2011 OpenStack, LLC.
# 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.

import operator

from nova.openstack.common import log as logging
from nova.scheduler import filters
from nova import utils


LOG = logging.getLogger(__name__)


class ComputeFilter(filters.BaseHostFilter):
    """HostFilter hard-coded to work with InstanceType records."""

    def _satisfies_extra_specs(self, capabilities, instance_type):
        """Check that the capabilities provided by the compute service
        satisfy the extra specs associated with the instance type"""
        if 'extra_specs' not in instance_type:
            return True

        LOG.debug(_("filter st"))

        # The following operations are supported:
        #   =, s==, s!=, s>=, s>, s<=, s<, <in>, <or>, ==, !=, >=, <=
        #   Note that <or> is handled in a different way below.
        op_methods = {'=': lambda x, y: (float(x) >= float(y)),
                      '<in>': lambda x, y: (x.find(y) != -1),
                      '==': lambda x, y: (float(x) == float(y)),
                      '!=': lambda x, y: (float(x) != float(y)),
                      '>=': lambda x, y: (float(x) >= float(y)),
                      '<=': lambda x, y: (float(x) <= float(y)),
                      's==': lambda x, y: operator.eq(x, y),
                      's!=': lambda x, y: operator.ne(x, y),
                      's<': lambda x, y: operator.lt(x, y),
                      's<=': lambda x, y: operator.le(x, y),
                      's>': lambda x, y: operator.gt(x, y),
                      's>=': lambda x, y: operator.ge(x, y)}

        LOG.debug(_("op"))
        cap_extra_specs = capabilities.get('instance_type_extra_specs', {})
        for key, req in instance_type['extra_specs'].iteritems():
            LOG.debug(_("key: %s, req:%s"), key, req)
            LOG.debug(_("type:%s"), type(req))
            cap = cap_extra_specs.get(key, None)
            if cap is None:
                return False
            if isinstance(req, (bool, int, long, float)):
                    if cap != req:
                        return False
            else:
                words = req.split()
                if len(words) == 1:
                    if cap != req:
                        return False
                else:
                    op = words[0]
                    method = op_methods.get(op)
                    new_req = words[1]
                    LOG.debug(_("type: %s, va=%s"), type(words[1]), str(words[1]))
                    for i in range(2, len(words)):
                        new_req += words[i]
                        LOG.debug(_("type: %s, va=%s"), type(words[i]), str(words[i]))

                    if op == '<or>':  # Ex: <or> v1 <or> v2 <or> v3
                        found = 0
                        for idx in range(1, len(words), 2):
                            if words[idx] == cap:
                                found = 1
                                break
                        if found == 0:
                            return False<commit_msg>another debuggin of PEP8 error<commit_after># Copyright (c) 2011 OpenStack, LLC.
# 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.

import operator

from nova.openstack.common import log as logging
from nova.scheduler import filters
from nova import utils


LOG = logging.getLogger(__name__)


class ComputeFilter(filters.BaseHostFilter):
    """HostFilter hard-coded to work with InstanceType records."""

    def _satisfies_extra_specs(self, capabilities, instance_type):
        """Check that the capabilities provided by the compute service
        satisfy the extra specs associated with the instance type"""
        if 'extra_specs' not in instance_type:
            return True

        LOG.debug(_("filter st"))

        # The following operations are supported:
        #   =, s==, s!=, s>=, s>, s<=, s<, <in>, <or>, ==, !=, >=, <=
        #   Note that <or> is handled in a different way below.
        op_methods = {'=': lambda x, y: (float(x) >= float(y)),
                      '<in>': lambda x, y: (x.find(y) != -1),
                      '==': lambda x, y: (float(x) == float(y)),
                      '!=': lambda x, y: (float(x) != float(y)),
                      '>=': lambda x, y: (float(x) >= float(y)),
                      '<=': lambda x, y: (float(x) <= float(y)),
                      's==': lambda x, y: operator.eq(x, y),
                      's!=': lambda x, y: operator.ne(x, y),
                      's<': lambda x, y: operator.lt(x, y),
                      's<=': lambda x, y: operator.le(x, y),
                      's>': lambda x, y: operator.gt(x, y),
                      's>=': lambda x, y: operator.ge(x, y)}

        LOG.debug(_("op"))
        cap_extra_specs = capabilities.get('instance_type_extra_specs', {})
        for key, req in instance_type['extra_specs'].iteritems():
            cap = cap_extra_specs.get(key, None)
            if cap is None:
                return False
            if isinstance(req, (bool, int, long, float)):
                    if cap != req:
                        return False
            else:
                words = req.split()
                if len(words) == 1:
                    if cap != req:
                        return False
                else:
                    op = words[0]
                    method = op_methods.get(op)
                    new_req = words[1]
                    for i in range(2, len(words)):
                        new_req += words[i]

                    if op == '<or>':  # Ex: <or> v1 <or> v2 <or> v3
                        found = 0
                        for idx in range(1, len(words), 2):
                            if words[idx] == cap:
                                found = 1
                                break
                        if found == 0:
                            return False
{'fraction_non_alphanumeric': 0.1251782149985743, 'fraction_numerical': 0.00641573994867408, 'mean_word_length': 1.5677159590043923, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1070292', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1880, 'n_words': 656}