<commit_before># -*- coding: utf-8 -*-
"""Defines the `Printer` class."""
from __future__ import print_function

import datetime
import sys
from builtins import input
from textwrap import fill

import numpy as np

from .utils import calculate_WAIC, is_integer, pretty_num

if sys.version_info[:2] < (3, 3):
    old_print = print  # noqa

    def print(*args, **kwargs):
        """Replacement for print function in Python 2.x."""
        flush = kwargs.pop('flush', False)
        old_print(*args, **kwargs)
        file = kwargs.get('file', sys.stdout)
        if flush and file is not None:
            file.flush()


class Printer(object):
    """Print class for MOSFiT."""

    class bcolors(object):
        """Special formatting characters."""

        HEADER = '\033[95m'
        OKBLUE = '\033[94m'
        OKGREEN = '\033[92m'
        WARNING = '\033[93m'
        FAIL = '\033[91m'
        ENDC = '\033[0m'
        BOLD = '\033[1m'
        UNDERLINE = '\033[4m'

    def __init__(self, pool=None, wrap_length=100, quiet=False):
        """Initialize printer, setting wrap length."""
        self._wrap_length = wrap_length
        self._quiet = quiet
        self._pool = pool

    def prt(self, text):
        """Print text without modification."""
        if self._quiet:
            return
        print(text)

    def inline(self, x, new_line=False, warning=False, error=False):
        """Print inline, erasing underlying pre-existing text."""
        if self._quiet:
            return
        lines = x.split('\n')
        if warning:
            sys.stdout.write(self.bcolors.WARNING)
        if error:
            sys.stdout.write(self.bcolors.FAIL)
        if not new_line:
            for line in lines:
                sys.stdout.write("\033[F")
                sys.stdout.write("\033[K")
        print(x, flush=True)
        if error or warning:
            sys.stdout.write(self.bcolors.ENDC)

    def wrapped(self, text, wrap_length=None, master_only=True, warning=False,
                error=False):
        """Print text wrapped to either the specified length or the default."""
        if self._quiet:
            return
        if wrap_length and is_integer(wrap_length):
            wl = wrap_length
        else:
            wl = self._wrap_length
        if master_only and self._pool and not self._pool.is_master():
            return
        if warning:
            sys.stdout.write(self.bcolors.WARNING)
        if error:
            sys.stdout.write(self.bcolors.FAIL)
        print(fill(text, wl))
        if error or warning:
            sys.stdout.write(self.bcolors.ENDC)

    def prompt(self, text, wrap_length=None, kind='bool', options=None):
        """Prompt the user for input and return a value based on response."""
        if wrap_length and is_integer(wrap_length):
            wl = wrap_length
        else:
            wl = self._wrap_length

        if kind == 'bool':
            choices = ' (y/[n])'
        elif kind == 'select':
            choices = '\n' + '\n'.join([
                ' ' + str(i + 1) + '.  ' + options[i] for i in range(
                    len(options))
            ] + [
                '[n]. None of the above, skip this event.\n'
                'Enter selection (' + ('1-' if len(options) > 1 else '') + str(
                    len(options)) + '/[n]):'
            ])
        elif kind == 'string':
            choices = ''
        else:
            raise ValueError('Unknown prompt kind.')

        prompt_txt = (text + choices).split('\n')
        for txt in prompt_txt[:-1]:
            ptxt = fill(txt, wl, replace_whitespace=False)
            print(ptxt)
        user_input = input(
            fill(
                prompt_txt[-1], wl, replace_whitespace=False) + " ")
        if kind == 'bool':
            return user_input in ["Y", "y", "Yes", "yes"]
        elif kind == 'select':
            if (is_integer(user_input) and
                    int(user_input) in list(range(1, len(options) + 1))):
                return options[int(user_input) - 1]
            return False
        elif kind == 'string':
            return user_input

    def status(self,
               fitter,
               desc='',
               scores='',
               accepts='',
               progress='',
               acor=None,
               fracking=False,
               messages=[]):
        """Print status message showing state of fitting process."""
        if self._quiet:
            return

        outarr = [fitter._event_name]
        if desc:
            outarr.append(desc)
        if isinstance(scores, list):
            scorestring = 'Fracking scores' if fracking else 'Score ranges'
            scorestring += ': [ ' + ', '.join([
                ' … '.join([
                    pretty_num(min(x))
                    if not np.isnan(min(x)) and np.isfinite(min(x))
                    else 'NaN',<commit_msg>BUG: trying to fix pesky unicode issues<commit_after># -*- coding: utf-8 -*-
"""Defines the `Printer` class."""
from __future__ import print_function

import datetime
import sys
from builtins import input
from textwrap import fill

import numpy as np

from .utils import calculate_WAIC, is_integer, pretty_num

if sys.version_info[:2] < (3, 3):
    old_print = print  # noqa

    def print(*args, **kwargs):
        """Replacement for print function in Python 2.x."""
        flush = kwargs.pop('flush', False)
        old_print(*args, **kwargs)
        file = kwargs.get('file', sys.stdout)
        if flush and file is not None:
            file.flush()


class Printer(object):
    """Print class for MOSFiT."""

    class bcolors(object):
        """Special formatting characters."""

        HEADER = '\033[95m'
        OKBLUE = '\033[94m'
        OKGREEN = '\033[92m'
        WARNING = '\033[93m'
        FAIL = '\033[91m'
        ENDC = '\033[0m'
        BOLD = '\033[1m'
        UNDERLINE = '\033[4m'

    def __init__(self, pool=None, wrap_length=100, quiet=False):
        """Initialize printer, setting wrap length."""
        self._wrap_length = wrap_length
        self._quiet = quiet
        self._pool = pool

    def prt(self, text):
        """Print text without modification."""
        if self._quiet:
            return
        print(text)

    def inline(self, x, new_line=False, warning=False, error=False):
        """Print inline, erasing underlying pre-existing text."""
        if self._quiet:
            return
        lines = x.split('\n')
        if warning:
            sys.stdout.write(self.bcolors.WARNING)
        if error:
            sys.stdout.write(self.bcolors.FAIL)
        if not new_line:
            for line in lines:
                sys.stdout.write("\033[F")
                sys.stdout.write("\033[K")
        print(x, flush=True)
        if error or warning:
            sys.stdout.write(self.bcolors.ENDC)

    def wrapped(self, text, wrap_length=None, master_only=True, warning=False,
                error=False):
        """Print text wrapped to either the specified length or the default."""
        if self._quiet:
            return
        if wrap_length and is_integer(wrap_length):
            wl = wrap_length
        else:
            wl = self._wrap_length
        if master_only and self._pool and not self._pool.is_master():
            return
        if warning:
            sys.stdout.write(self.bcolors.WARNING)
        if error:
            sys.stdout.write(self.bcolors.FAIL)
        print(fill(text, wl))
        if error or warning:
            sys.stdout.write(self.bcolors.ENDC)

    def prompt(self, text, wrap_length=None, kind='bool', options=None):
        """Prompt the user for input and return a value based on response."""
        if wrap_length and is_integer(wrap_length):
            wl = wrap_length
        else:
            wl = self._wrap_length

        if kind == 'bool':
            choices = ' (y/[n])'
        elif kind == 'select':
            choices = '\n' + '\n'.join([
                ' ' + str(i + 1) + '.  ' + options[i] for i in range(
                    len(options))
            ] + [
                '[n]. None of the above, skip this event.\n'
                'Enter selection (' + ('1-' if len(options) > 1 else '') + str(
                    len(options)) + '/[n]):'
            ])
        elif kind == 'string':
            choices = ''
        else:
            raise ValueError('Unknown prompt kind.')

        prompt_txt = (text + choices).split('\n')
        for txt in prompt_txt[:-1]:
            ptxt = fill(txt, wl, replace_whitespace=False)
            print(ptxt)
        user_input = input(
            fill(
                prompt_txt[-1], wl, replace_whitespace=False) + " ")
        if kind == 'bool':
            return user_input in ["Y", "y", "Yes", "yes"]
        elif kind == 'select':
            if (is_integer(user_input) and
                    int(user_input) in list(range(1, len(options) + 1))):
                return options[int(user_input) - 1]
            return False
        elif kind == 'string':
            return user_input

    def status(self,
               fitter,
               desc='',
               scores='',
               accepts='',
               progress='',
               acor=None,
               fracking=False,
               messages=[]):
        """Print status message showing state of fitting process."""
        if self._quiet:
            return

        outarr = [fitter._event_name]
        if desc:
            outarr.append(desc)
        if isinstance(scores, list):
            scorestring = 'Fracking scores' if fracking else 'Score ranges'
            scorestring += ': [ ' + ', '.join([
                u' … '.join([
                    pretty_num(min(x))
                    if not np.isnan(min(x)) and np.isfinite(min(x))
                    else 'NaN',
{'fraction_non_alphanumeric': 0.12310663820270408, 'fraction_numerical': 0.011995527091592965, 'mean_word_length': 1.674096221799402, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6297749', 'n_tokens_mistral': 2897, 'n_tokens_neox': 2755, 'n_words': 768}