<commit_before># -*- coding: UTF-8 -*-
"""
Capture output (stdout, stderr), logs, etc.
"""

from __future__ import absolute_import
from contextlib import contextmanager
import sys
from six import StringIO
from behave.log_capture import LoggingCapture
from behave.textutil import text as _text

def add_text_to(value, more_text, separator="\n"):
    if more_text:
        if value:
            if separator and not value.endswith(separator):
                value += separator
            value += more_text
        else:
            value = more_text
    return value


class Captured(object):
    """Stores and aggregates captured output data."""
    empty = u""
    linesep = u"\n"

    def __init__(self, stdout=None, stderr=None, log_output=None):
        self.stdout = stdout or self.empty
        self.stderr = stderr or self.empty
        self.log_output = log_output or self.empty

    def reset(self):
        self.stdout = self.empty
        self.stderr = self.empty
        self.log_output = self.empty

    # -- PYTHON2:
    def __nonzero__(self):
        return bool(self.stdout or self.stderr or self.log_output)
    __bool__ = __nonzero__     # -- FOR: PYTHON3

    @property
    def output(self):
        """Makes a simple report of the captured data by concatenating
        all parts.
        """
        output_text = self.stdout
        output_text = add_text_to(output_text, self.stderr)
        output_text = add_text_to(output_text, self.log_output)
        return output_text

    def add(self, captured):
        """Adds/appends captured output data to this object.

        :param captured:    Captured object whose data should be added.
        :return: self, to allow daisy-chaining (if needed).
        """
        assert isinstance(captured, Captured)
        self.stdout = add_text_to(self.stdout, captured.stdout, self.linesep)
        self.stderr = add_text_to(self.stderr, captured.stderr, self.linesep)
        self.log_output = add_text_to(self.log_output, captured.log_output,
                                      self.linesep)
        return self

    def make_report(self):
        """Makes a detailled report of the captured output data.

        :returns: Report as string.
        """
        report_parts = []<commit_msg>FIX: Python3 problem on Linux CI server.<commit_after># -*- coding: UTF-8 -*-
"""
Capture output (stdout, stderr), logs, etc.
"""

from __future__ import absolute_import
from contextlib import contextmanager
import sys
from six import StringIO, PY2
from behave.log_capture import LoggingCapture
from behave.textutil import text as _text

def add_text_to(value, more_text, separator="\n"):
    if more_text:
        if value:
            if separator and not value.endswith(separator):
                value += separator
            value += more_text
        else:
            value = more_text
    return value


class Captured(object):
    """Stores and aggregates captured output data."""
    empty = u""
    linesep = u"\n"

    def __init__(self, stdout=None, stderr=None, log_output=None):
        self.stdout = stdout or self.empty
        self.stderr = stderr or self.empty
        self.log_output = log_output or self.empty

    def reset(self):
        self.stdout = self.empty
        self.stderr = self.empty
        self.log_output = self.empty

    # -- PYTHON2:
    if PY2:
        def __nonzero__(self):
            return bool(self.stdout or self.stderr or self.log_output)
    else:
        def __bool__(self):
            return bool(self.stdout or self.stderr or self.log_output)

    @property
    def output(self):
        """Makes a simple report of the captured data by concatenating
        all parts.
        """
        output_text = self.stdout
        output_text = add_text_to(output_text, self.stderr)
        output_text = add_text_to(output_text, self.log_output)
        return output_text

    def add(self, captured):
        """Adds/appends captured output data to this object.

        :param captured:    Captured object whose data should be added.
        :return: self, to allow daisy-chaining (if needed).
        """
        assert isinstance(captured, Captured)
        self.stdout = add_text_to(self.stdout, captured.stdout, self.linesep)
        self.stderr = add_text_to(self.stderr, captured.stderr, self.linesep)
        self.log_output = add_text_to(self.log_output, captured.log_output,
                                      self.linesep)
        return self

    def make_report(self):
        """Makes a detailled report of the captured output data.

        :returns: Report as string.
        """
        report_parts = []
{'fraction_non_alphanumeric': 0.08875484704868591, 'fraction_numerical': 0.0017233950883239983, 'mean_word_length': 2.3596237337192476, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6390722', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1304, 'n_words': 392}