<commit_before>
import os
from getpass import getpass

from addic7ed.error import Error
from addic7ed.util import remove_extension, file_to_query, string_set
from addic7ed.episode import search
from addic7ed.compat import echo, input
from addic7ed.login import login


class UI(object):

    def __init__(self, args):
        self.args = args

    @property
    def batch(self):
        return self.args.batch or self.args.brute_batch

    def select(self, choices):
        if not choices:
            raise Error("Internal error: no choices!")

        if len(choices) == 1 or self.batch:
            result = 1

        else:
            just = len(str(len(choices)))
            index = 1
            for choice in choices:
                echo(str(index).rjust(just), ':', choice)
                index += 1

            while True:
                try:
                    result = int(input('> '))

                except ValueError:
                    result = None

                if result and 1 <= result <= len(choices):
                    break

                else:
                    echo("Bad response")

        result = choices[result - 1]
        echo(result)
        return result

    def confirm(self, question):
        question += ' [yn]> '

        if self.batch:
            return True

        while True:
            answer = input(question)
            if answer in 'yn':
                break

            else:
                echo('Bad answer')

        return answer == 'y'


class SearchUI(UI):

    def episode(self, episode, languages=[], releases=[]):
        episode.fetch_versions()
        versions = episode.filter_versions(languages, releases, True,
                                           self.args.hearing_impaired)
        return self.select(versions)

    def launch_file(self, filename):
        echo('-' * 30)
        args = self.args
        filename = remove_extension(filename) + '.srt'

        echo('Target SRT file:', filename)
        ignore = False
        if os.path.isfile(filename):
            echo('File exists.', end=' ')
            if args.ignore or (not args.overwrite and
                               not self.confirm('Overwrite?')):
                echo('Ignoring.')<commit_msg>Default responses for inputs<commit_after>
import os
from getpass import getpass

from addic7ed.error import Error
from addic7ed.util import remove_extension, file_to_query, string_set
from addic7ed.episode import search
from addic7ed.compat import echo, input
from addic7ed.login import login


class UI(object):

    def __init__(self, args):
        self.args = args

    @property
    def batch(self):
        return self.args.batch or self.args.brute_batch

    def select(self, choices):
        if not choices:
            raise Error("Internal error: no choices!")

        if len(choices) == 1 or self.batch:
            result = 1

        else:
            just = len(str(len(choices)))
            index = 1
            for choice in choices:
                echo(str(index).rjust(just), ':', choice)
                index += 1

            while True:
                answer = input('[1] > ')
                if not answer:
                    result = 1

                else:
                    try:
                        result = int(answer)

                    except ValueError:
                        result = None

                if result and 1 <= result <= len(choices):
                    break

                else:
                    echo("Bad response")

        result = choices[result - 1]
        echo(result)
        return result

    def confirm(self, question, default=None):
        responses = 'yn' if default is None else 'Yn' if default else 'yN'
        question += ' [{}] > '.format(responses)

        if self.batch:
            return True

        while True:
            answer = input(question)
            if answer in ('y', 'n'):
                return answer == 'y'

            elif answer == '' and default is not None:
                return default

            else:
                echo('Bad answer')


class SearchUI(UI):

    def episode(self, episode, languages=[], releases=[]):
        episode.fetch_versions()
        versions = episode.filter_versions(languages, releases, True,
                                           self.args.hearing_impaired)
        return self.select(versions)

    def launch_file(self, filename):
        echo('-' * 30)
        args = self.args
        filename = remove_extension(filename) + '.srt'

        echo('Target SRT file:', filename)
        ignore = False
        if os.path.isfile(filename):
            echo('File exists.', end=' ')
            if args.ignore or (not args.overwrite and
                               not self.confirm('Overwrite?', True)):
                echo('Ignoring.')
{'fraction_non_alphanumeric': 0.0949341021416804, 'fraction_numerical': 0.005766062602965404, 'mean_word_length': 1.5244282744282744, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5765823', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1212, 'n_words': 371}