<commit_before>""" PluginRunner runs all transactions through applicable checkers.
"""
from pluginDBAPI import DBAPI
import marisa_trie
from multiprocessing import Process


class PluginRunner(object):
    """ PluginRunner runs all transactions through applicable checkers.
        A transaction is checked by a plugin if it is accepted by both
        uri acceptor and content-type acceptor.
        For acceptors, uri is changed to the longest prefix based on
        plugin's configuration using trie.
    """
    def __init__(self, dbconf, uriAcceptor, typeAcceptor, maxDepth):
        self.dbconf = dbconf
        self.pluginsById = {}
        self.uriAcceptor = uriAcceptor
        self.typeAcceptor = typeAcceptor
        self.maxDepth = maxDepth

    @staticmethod
    def runPlugin(plugin, info):
        plugin.check(info.getId(), info.getContent().encode('utf-8'))

    def runTransaction(self, plugins, info, prefix):
        """ Run a single transaction through all plugins where it's accepted.
        """
        # get list of plugins to use
        # create processes to run each plugin
        processes = []
        for plugin in plugins:
            fakeTransaction = info
            fakeTransaction.setUri(prefix)
            if self.accept(plugin.getId(), fakeTransaction):
                print plugin.getId()
                if special_setup(plugin.getId()):
                    plugin.setDepth(info.getDepth())
                    plugin.setMaxDepth(self.maxDepth)
                p = Process(target=PluginRunner.runPlugin, args=(plugin, info))
                processes.append(p)
        for process in processes:
            process.start()
        for process in processes:
            process.join()

    def special_setup(self, pluginId):
        return (pluginId == "linksFinder") or (pluginId == "formChecker")

    def run(self, plugins):
        """ Run all transactions through all plugins where it's accepted.
        """

        print "Running checker"
        api = DBAPI(self.dbconf)
        for plugin in plugins:
            plugin.setDb(api)
            self.pluginsById[plugin.getId()] = plugin
            if plugin.getId() == "linksFinder":
                plugin.setTypes(self.typeAcceptor.getValues())
                plugin.setUris(self.uriAcceptor.getValues())

        info = api.getTransaction()
        while info.getId() != -1:<commit_msg>Minor fix<commit_after>""" PluginRunner runs all transactions through applicable checkers.
"""
from pluginDBAPI import DBAPI
import marisa_trie
from multiprocessing import Process


class PluginRunner(object):
    """ PluginRunner runs all transactions through applicable checkers.
        A transaction is checked by a plugin if it is accepted by both
        uri acceptor and content-type acceptor.
        For acceptors, uri is changed to the longest prefix based on
        plugin's configuration using trie.
    """
    def __init__(self, dbconf, uriAcceptor, typeAcceptor, maxDepth):
        self.dbconf = dbconf
        self.pluginsById = {}
        self.uriAcceptor = uriAcceptor
        self.typeAcceptor = typeAcceptor
        self.maxDepth = maxDepth

    @staticmethod
    def runPlugin(plugin, info):
        plugin.check(info.getId(), info.getContent().encode('utf-8'))

    def runTransaction(self, plugins, info, prefix):
        """ Run a single transaction through all plugins where it's accepted.
        """
        # get list of plugins to use
        # create processes to run each plugin
        processes = []
        for plugin in plugins:
            fakeTransaction = info
            fakeTransaction.setUri(prefix)
            if self.accept(plugin.getId(), fakeTransaction):
                print(plugin.getId())
                if special_setup(plugin.getId()):
                    plugin.setDepth(info.getDepth())
                    plugin.setMaxDepth(self.maxDepth)
                p = Process(target=PluginRunner.runPlugin, args=(plugin, info))
                processes.append(p)
        for process in processes:
            process.start()
        for process in processes:
            process.join()

    def special_setup(self, pluginId):
        return (pluginId == "linksFinder") or (pluginId == "formChecker")

    def run(self, plugins):
        """ Run all transactions through all plugins where it's accepted.
        """

        print "Running checker"
        api = DBAPI(self.dbconf)
        for plugin in plugins:
            plugin.setDb(api)
            self.pluginsById[plugin.getId()] = plugin
            if plugin.getId() == "linksFinder":
                plugin.setTypes(self.typeAcceptor.getValues())
                plugin.setUris(self.uriAcceptor.getValues())

        info = api.getTransaction()
        while info.getId() != -1:
{'fraction_non_alphanumeric': 0.0903198829186703, 'fraction_numerical': 0.00083629521220991, 'mean_word_length': 2.265529010238908, 'pattern_counts': {'":': 2, '<': 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': '1333068', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1199, 'n_words': 365}