<commit_before>import common
import errno
import inspect
import logging
import os
import sys
logger = logging.getLogger(__name__)

class InvalidSetup(common.AppException): pass

def available():
    return [i[0] for i in inspect.getmembers(sys.modules[__name__], inspect.isclass)
                if issubclass(i[1], _Outputter) and not i[0].startswith('_')]
    
class _Outputter(object):
    def __init__(self, argument, formatter, wiki):
        """Setup new outputter and validate inputs
        Params:
            argument (str): argument pass on command line
            multiple_files (bool): whether output will be in multiple files
        
        """
        
        self.argument = argument
        self.multiple_files = formatter.MULTIPLE_FILES
        self.formatter = formatter
        self.wiki = wiki
        self._validate()
    
    def _validate(self):
        pass 
        
class File(_Outputter):
    def __call__(self, output):
        logger.debug(output)
        if self.multiple_files:
            try:
                os.mkdir(self.argument)
            except OSError as e:
                if e.errno != errno.EEXIST or os.path.isfile(self.argument):
                    raise 
            for name, content in output.iteritems():
                self._write_file(os.path.join(self.argument,
                        name+self.formatter.FILE_EXT), content)
        else:
            self._write_file(self.argument, output)
                
    def _write_file(self, name, content):
        with open(name, 'w') as f:
            f.write(content.encode('UTF-8'))
        
    def _validate(self):
        if not self.argument:
            raise InvalidSetup('Need to pass path to file')

class Stdout(_Outputter):
    def __call__(self, text):
        print(text)
    
    def _validate(self):
        if self.multiple_files:
            raise InvalidSetup(
                    'Stdout needs format where only single file produced')<commit_msg>Add base wiki output requiring login<commit_after>import common
import errno
import inspect
import logging
import os
import sys
logger = logging.getLogger(__name__)

class InvalidSetup(common.AppException): pass

def available():
    return [i[0] for i in inspect.getmembers(sys.modules[__name__], inspect.isclass)
                if issubclass(i[1], _Outputter) and not i[0].startswith('_')]
    
class _Outputter(object):
    def __init__(self, argument, formatter, wiki):
        """Setup new outputter and validate inputs
        Params:
            argument (str): argument pass on command line
            multiple_files (bool): whether output will be in multiple files
        
        """
        
        self.argument = argument
        self.multiple_files = formatter.MULTIPLE_FILES
        self.formatter = formatter
        self.wiki = wiki
        self._validate()
    
    def _validate(self):
        pass 
        
class File(_Outputter):
    def __call__(self, output):
        logger.debug(output)
        if self.multiple_files:
            try:
                os.mkdir(self.argument)
            except OSError as e:
                if e.errno != errno.EEXIST or os.path.isfile(self.argument):
                    raise 
            for name, content in output.iteritems():
                self._write_file(os.path.join(self.argument,
                        name+self.formatter.FILE_EXT), content)
        else:
            self._write_file(self.argument, output)
                
    def _write_file(self, name, content):
        with open(name, 'w') as f:
            f.write(content.encode('UTF-8'))
        
    def _validate(self):
        if not self.argument:
            raise InvalidSetup('Need to pass path to file')

class Stdout(_Outputter):
    def __call__(self, text):
        print(text)
    
    def _validate(self):
        if self.multiple_files:
            raise InvalidSetup(
                    'Stdout needs format where only single file produced')
            
class Wiki(_Outputter):
    def _validate(self):
        if not self.wiki.logged_in:
            raise InvalidSetup('Need login to edit wiki')
        if not self.multiple_files:
            raise InvalidSetup('Must edit multiple wiki pages')
{'fraction_non_alphanumeric': 0.08690504380771963, 'fraction_numerical': 0.001894387875917594, 'mean_word_length': 2.0128388017118404, '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': '7293295', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1117, 'n_words': 320}