<commit_before># -*- test-case-name: vumi.tests.test_servicemaker -*-
import os
import sys
import warnings

import yaml
from zope.interface import implements
from twisted.python import usage
from twisted.application.service import IServiceMaker
from twisted.plugin import IPlugin

from vumi.service import WorkerCreator
from vumi.utils import (load_class_by_string,
                        generate_worker_id)
from vumi.errors import VumiError
from vumi.sentry import SentryLoggerService


class SafeLoaderWithInclude(yaml.SafeLoader):
    def __init__(self, *args, **kwargs):
        super(SafeLoaderWithInclude, self).__init__(*args, **kwargs)
        self._root = os.path.split(self.stream.name)[0]
        self.add_constructor('!include', self._include)

    def _include(self, loader, node):
        filename = os.path.join(self._root, self.construct_scalar(node))
        filename = os.path.normpath(filename)
        with open(filename) as f:
            return yaml.load(f, Loader=SafeLoaderWithInclude)


def overlay_configs(*configs):
    """Non-recursively overlay a set of configuration dictionaries"""
    config = {}

    for overlay in configs:<commit_msg>Default to current directory if the stream is not a file<commit_after># -*- test-case-name: vumi.tests.test_servicemaker -*-
import os
import sys
import warnings

import yaml
from zope.interface import implements
from twisted.python import usage
from twisted.application.service import IServiceMaker
from twisted.plugin import IPlugin

from vumi.service import WorkerCreator
from vumi.utils import (load_class_by_string,
                        generate_worker_id)
from vumi.errors import VumiError
from vumi.sentry import SentryLoggerService


class SafeLoaderWithInclude(yaml.SafeLoader):
    def __init__(self, *args, **kwargs):
        super(SafeLoaderWithInclude, self).__init__(*args, **kwargs)
        self.add_constructor('!include', self._include)
        if isinstance(self.stream, file):
            self._root = os.path.dirname(self.stream.name)
        else:
            self._root = os.path.curdir

    def _include(self, loader, node):
        filename = os.path.join(self._root, self.construct_scalar(node))
        filename = os.path.normpath(filename)
        with open(filename) as f:
            return yaml.load(f, Loader=SafeLoaderWithInclude)


def overlay_configs(*configs):
    """Non-recursively overlay a set of configuration dictionaries"""
    config = {}

    for overlay in configs:
{'fraction_non_alphanumeric': 0.09178743961352658, 'fraction_numerical': 0.00040257648953301127, 'mean_word_length': 3.6710526315789473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1265407', 'n_tokens_mistral': 718, 'n_tokens_neox': 691, 'n_words': 189}