<commit_before>"""Pyzor check plugin."""

from __future__ import absolute_import

import pyzor.client
import pyzor.digest

import pad.plugins.base


class PyzorPlugin(pad.plugins.base.BasePlugin):
    eval_rules = ("check_pyzor",)
    options = {"use_pyzor": ("bool", True),
               "pyzor_max": ("int", 5),
               "pyzor_timeout": ("float", 3.5),
               "pyzor_servers": ("list", ["public.pyzor.org:24441"])}

    def finish_parsing_end(self, ruleset):
        """Create and store globally a pyzor client."""
        super(PyzorPlugin, self).finish_parsing_end(ruleset)
        # Store a single Pyzor client in the global context at plugin
        # initialization, rather than creating a new one for every message
        self["client"] = pyzor.client.BatchClient(self["pyzor_timeout"])

    def check_pyzor(self, msg, target=None):
        """Check the message with the defined pyzor servers. Stores the
        digest so it can be used
        """
        if not self["use_pyzor"]:
            return False
        digest = pyzor.digest.DataDigester(msg.msg).value<commit_msg>Fix Pyzor client timeout argument<commit_after>"""Pyzor check plugin."""

from __future__ import absolute_import

import pyzor.client
import pyzor.digest

import pad.plugins.base


class PyzorPlugin(pad.plugins.base.BasePlugin):
    eval_rules = ("check_pyzor",)
    options = {"use_pyzor": ("bool", True),
               "pyzor_max": ("int", 5),
               "pyzor_timeout": ("float", 3.5),
               "pyzor_servers": ("list", ["public.pyzor.org:24441"])}

    def finish_parsing_end(self, ruleset):
        """Create and store globally a pyzor client."""
        super(PyzorPlugin, self).finish_parsing_end(ruleset)
        # Store a single Pyzor client in the global context at plugin
        # initialization, rather than creating a new one for every message
        self["client"] = pyzor.client.BatchClient(
            timeout=self["pyzor_timeout"]
        )

    def check_pyzor(self, msg, target=None):
        """Check the message with the defined pyzor servers. Stores the
        digest so it can be used
        """
        if not self["use_pyzor"]:
            return False
        digest = pyzor.digest.DataDigester(msg.msg).value
{'fraction_non_alphanumeric': 0.11569148936170212, 'fraction_numerical': 0.0070921985815602835, 'mean_word_length': 2.8713550600343054, 'pattern_counts': {'":': 8, '<': 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': '3669145', 'n_tokens_mistral': 704, 'n_tokens_neox': 681, 'n_words': 188}