<commit_before># Copyright 2015 - Mirantis, Inc.
#
#    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.

from oslo_config import cfg
import oslo_messaging as messaging

from mistral import exceptions as exc
from mistral import utils


CONF = cfg.CONF
CONF.import_opt('rpc_response_timeout', 'mistral.config')


def get_rpc_info_from_oslo(additional_conf=None):
    transport = messaging.TransportURL.parse(CONF, CONF.transport_url)

    rpc_backend = _get_rpc_backend(transport)

    conf_dict = _get_rpc_info(rpc_backend, transport)

    return utils.merge_dicts(conf_dict, _get_extra_info(additional_conf, ))


def _get_rpc_backend(transport):
    if transport:
        return transport.transport

    return CONF.rpc_backend


def _get_rpc_info(rpc_backend, transport):

    if rpc_backend in ['amqp', 'zmq']:
        return {}
    elif transport and len(transport.hosts) == 1:
        # TODO(ddeja): Handle multiple hosts.
        return _get_rpc_info_from_transport_url(transport, rpc_backend)
    elif rpc_backend in ['rabbit', 'fake']:
        return _get_rabbit_info_from_oslo()
    else:
        raise exc.MistralException(
            'Mistral cannot run with rpc_backend %s' % rpc_backend
        )


def _get_rpc_info_from_transport_url(transport, rpc_backend):
    if rpc_backend in ['rabbit', 'fake']:
        durable_queues = CONF.oslo_messaging_rabbit.amqp_durable_queues
        auto_delete = CONF.oslo_messaging_rabbit.amqp_auto_delete
    else:
        raise exc.MistralException(
            'Mistral cannot run with rpc_backend %s' % rpc_backend
        )

    transport_host = transport.hosts[0]
<commit_msg>Stop excpecting to have rabbit flags set when using fake driver<commit_after># Copyright 2015 - Mirantis, Inc.
#
#    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.

from oslo_config import cfg
import oslo_messaging as messaging

from mistral import exceptions as exc
from mistral import utils


CONF = cfg.CONF
CONF.import_opt('rpc_response_timeout', 'mistral.config')


def get_rpc_info_from_oslo(additional_conf=None):
    transport = messaging.TransportURL.parse(CONF, CONF.transport_url)

    rpc_backend = _get_rpc_backend(transport)

    conf_dict = _get_rpc_info(rpc_backend, transport)

    return utils.merge_dicts(conf_dict, _get_extra_info(additional_conf, ))


def _get_rpc_backend(transport):
    if transport:
        return transport.transport

    return CONF.rpc_backend


def _get_rpc_info(rpc_backend, transport):

    if rpc_backend in ['amqp', 'zmq']:
        return {}
    elif transport and len(transport.hosts) == 1:
        # TODO(ddeja): Handle multiple hosts.
        return _get_rpc_info_from_transport_url(transport, rpc_backend)
    elif rpc_backend == 'rabbit':
        return _get_rabbit_info_from_oslo()
    elif rpc_backend == 'fake':
        return {}
    else:
        raise exc.MistralException(
            'Mistral cannot run with rpc_backend %s' % rpc_backend
        )


def _get_rpc_info_from_transport_url(transport, rpc_backend):
    if rpc_backend in ['rabbit', 'fake']:
        durable_queues = CONF.oslo_messaging_rabbit.amqp_durable_queues
        auto_delete = CONF.oslo_messaging_rabbit.amqp_auto_delete
    else:
        raise exc.MistralException(
            'Mistral cannot run with rpc_backend %s' % rpc_backend
        )

    transport_host = transport.hosts[0]

{'fraction_non_alphanumeric': 0.07432740538075695, 'fraction_numerical': 0.004559963520291838, 'mean_word_length': 3.6178947368421053, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7218032', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1315, 'n_words': 392}