<commit_before>import asyncio

from aioworkers.core.base import AbstractEntity


class AbstractReader(AbstractEntity):
    async def get(self):
        raise NotImplementedError()


class AbstractWriter(AbstractEntity):
    async def put(self, value):
        raise NotImplementedError()


class AbstractQueue(AbstractReader, AbstractWriter):
    pass


class Queue(asyncio.Queue, AbstractQueue):
    def __init__(self, config, *, context=None, loop=None):
        maxsize = config.get('maxsize', 0)
        AbstractQueue.__init__(self, config, context=context, loop=loop)
        asyncio.Queue.__init__(self, maxsize=maxsize, loop=loop)


class PriorityQueue(asyncio.PriorityQueue, AbstractQueue):
    def __init__(self, config, *, context=None, loop=None):
        maxsize = config.get('maxsize', 0)
        AbstractQueue.__init__(self, config, context=context, loop=loop)
        asyncio.Queue.__init__(self, maxsize=maxsize, loop=loop)<commit_msg>ScoreQueueMixin<commit_after>import asyncio
from abc import abstractmethod

from ..core.base import AbstractEntity
from ..utils import import_name


class AbstractReader(AbstractEntity):
    @abstractmethod  # pragma: no cover
    async def get(self):
        raise NotImplementedError()


class AbstractWriter(AbstractEntity):
    @abstractmethod  # pragma: no cover
    async def put(self, value):
        raise NotImplementedError()


class AbstractQueue(AbstractReader, AbstractWriter):
    pass


class Queue(asyncio.Queue, AbstractQueue):
    def __init__(self, config, *, context=None, loop=None):
        maxsize = config.get('maxsize', 0)
        AbstractQueue.__init__(self, config, context=context, loop=loop)
        asyncio.Queue.__init__(self, maxsize=maxsize, loop=loop)

    def __len__(self):
        return len(self._queue)


class PriorityQueue(asyncio.PriorityQueue, Queue):
    def __init__(self, config, *, context=None, loop=None):
        maxsize = config.get('maxsize', 0)
        AbstractQueue.__init__(self, config, context=context, loop=loop)
        asyncio.Queue.__init__(self, maxsize=maxsize, loop=loop)


class ScoreQueueMixin:
    """
    config:
        default_score: default value score
    """

    def init(self):
        self._default_score = self.config.get(
            'default_score', self.default_score)
        if isinstance(self._default_score, str):
            self._default_score = import_name(self._default_score)
        return super().init()

    def put(self, value, score=None):
        if score is None:
            if callable(self._default_score):
                score = self._default_score()
        v = score, value
        return super().put(v)

    async def get(self, score=False):
        s, val = await super().get()
        if score:
            return val, s
        else:
            return val


def score_queue(default_score=None):
    return lambda klass: type(
        klass.__name__,
        (ScoreQueueMixin, klass),
        {'default_score': default_score, 'super': klass}
    )


@score_queue()
class ScoreQueue(PriorityQueue):
    pass
{'fraction_non_alphanumeric': 0.10476501305483028, 'fraction_numerical': 0.0013054830287206266, 'mean_word_length': 3.32909604519774, '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': '3066112', 'n_tokens_mistral': 886, 'n_tokens_neox': 866, 'n_words': 211}