<commit_before>from twisted.application import service
from functools import wraps

class BasePlugin(object, service.Service):
    def setServiceParent(self, parent):
        try:
            setUp = getattr(self, 'setUp')
        except AttributeError:
            pass
        else:
            if callable(setUp):
                setUp()
        return service.Service.setServiceParent(self, parent)
        
    def disownServiceParent(self):
        try:
            tearDown = getattr(self, 'tearDown')
        except AttributeError:
            pass
        else:
            if callable(tearDown):
                tearDown()
        return service.Service.disownServiceParent(self)

def plugin_method(arg=None):
    if callable(arg):
        return PluginMethod(function=arg)
    def wrapper(function):
        if arg is not None:
            return PluginMethod(function=function, priority=arg)
        else:
            return PluginMethod(function=function)
    return wrapper

class PluginMethod(object):
    priority_mapping = {'high':0, 'normal':1, 'low':2}
    def __init__(self, function, priority='normal'):
        if priority not in self.priority_mapping:
            raise ValueError("%s is not an accepted priority" % priority)
        self.function = function
        self.priority = priority
        super(PluginMethod, self).__init__()
        
    @property
    def num_priority(self):
        return self.priority_mapping[self.priority]

    def __call__(self, *args, **kwargs):
        return self.function(*args, **kwargs)


    def __lt__(self, other):
        if self.num_priority < other.num_priority:
            return True
        return False

    def __eq__(self, other):
        if self.num_priority != other.num_priority:
            return False
        if str(self) != str(other):
            return False
        return True

    def __gt__(self, other):
        if self.num_priority > other.num_priority:
            return True
        return False

    def __le__(self, other):
        return self.__lt__(other) or self.__eq__(other)<commit_msg>Fix plugin handling<commit_after>from twisted.application import service
from functools import wraps
import types

class BasePlugin(object, service.Service):
    def setServiceParent(self, parent):
        try:
            setUp = getattr(self, 'setUp')
        except AttributeError:
            pass
        else:
            if callable(setUp):
                setUp()
        return service.Service.setServiceParent(self, parent)
        
    def disownServiceParent(self):
        try:
            tearDown = getattr(self, 'tearDown')
        except AttributeError:
            pass
        else:
            if callable(tearDown):
                tearDown()
        return service.Service.disownServiceParent(self)

def plugin_method(arg=None):
    if callable(arg):
        return PluginMethod(function=arg)
    def wrapper(function):
        if arg is not None:
            return PluginMethod(function=function, priority=arg)
        else:
            return PluginMethod(function=function)
    return wrapper

class PluginMethod(object):
    priority_mapping = {'high':0, 'normal':1, 'low':2}
    def __init__(self, function, priority='normal'):
        if priority not in self.priority_mapping:
            raise ValueError("%s is not an accepted priority" % priority)
        self.function = function
        self.priority = priority
        super(PluginMethod, self).__init__()
        
    @property
    def num_priority(self):
        return self.priority_mapping[self.priority]

    def __call__(self, *args, **kwargs):
        return self.function(*args, **kwargs)

    def __get__(self, obj, objtype=None):
         "Simulate func_descr_get() in Objects/funcobject.c"
         return types.MethodType(self, obj, objtype)

    def __lt__(self, other):
        if self.num_priority < other.num_priority:
            return True
        return False

    def __eq__(self, other):
        if self.num_priority != other.num_priority:
            return False
        if str(self) != str(other):
            return False
        return True

    def __gt__(self, other):
        if self.num_priority > other.num_priority:
            return True
        return False

    def __le__(self, other):
        return self.__lt__(other) or self.__eq__(other)
{'fraction_non_alphanumeric': 0.08844475074661154, 'fraction_numerical': 0.0013783597518952446, 'mean_word_length': 2.2541106128550075, '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': '950364', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1150, 'n_words': 309}