<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import redis

from pimpamqueues import QUEUE_COLLECTION_OF_ELEMENTS

from pimpamqueues import Tools
from pimpamqueues.exceptions import PimPamQueuesError
from pimpamqueues.exceptions import PimPamQueuesElementWithoutValueError


class SimpleQueue(object):
    '''
    A lightweight queue. Simple Queue.
    '''

    QUEUE_TYPE_NAME = 'simple'

    def __init__(self, id_args=[], collection_of=QUEUE_COLLECTION_OF_ELEMENTS,
                 keep_previous=True, redis_conn=None):
        '''
        Create a SimpleQueue object.

        Arguments:
        :id_args -- list, list's values will be used to name the queue
        :collection_of -- string (default: QUEUE_COLLECTION_OF_ELEMENTS),
                          a type descriptor of queued elements
        :keep_previous -- boolean (default: true),
                          a flag to create a fresh queue or not
        :redis_conn -- redis.client.Redis (default: None), a redis
                       connection will be created using the default
                       redis.client.Redis connection params.
        '''
        self.id_args = id_args
        self.collection_of = collection_of

        if redis_conn is None:
            redis_conn = redis.Redis()
        self.redis = redis_conn

        self.key_queue = self.get_key_queue()

        if keep_previous is False:
            self.delete()

    def __str__(self):
        '''
        Return a string representation of the class.

        Returns: string
        '''
        return '<SimpleQueue: %s (%s)>' % (self.key_queue, self.num())

    def get_key_queue(self):
        '''
        Get a key id that will be used to store/retrieve data from
        the redis server.

        Returns: string
        '''
        return 'queue:%s:type:%s:of:%s' % ('.'.join(self.id_args),
                                           SimpleQueue.QUEUE_TYPE_NAME,
                                           self.collection_of)

    def push(self, element, to_first=False):
        '''
        Push a element into the queue. Element can be pushed to the first or
        last position (by default is pushed to the last position).

        Arguments:
        :element -- string
        :to_first -- boolean (default: False)

        Returns: long, the number of queued elements
        '''
        if element in ('', None):
            raise PimPamQueuesElementWithoutValueError()
        return self._push_to_queue(element, to_first)

    def push_some(self, elements, to_first=False, num_block_size=None):
        '''
        Push a bunch of elements into the queue. Elements can be pushed to the
        first or last position (by default are pushed to the last position).

        Arguments:
        :elements -- a collection of strings
        :to_first -- boolean (default: false)
        :num_block_size -- integer (default: none)

        Returns: long, the number of queued elements
        '''
        return self._push_some_to_queue(elements, to_first, num_block_size)

    def pop(self, last=False):<commit_msg>included PimPamQueuesElementWithoutValueError in push() docstring<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import redis

from pimpamqueues import QUEUE_COLLECTION_OF_ELEMENTS

from pimpamqueues import Tools
from pimpamqueues.exceptions import PimPamQueuesError
from pimpamqueues.exceptions import PimPamQueuesElementWithoutValueError


class SimpleQueue(object):
    '''
    A lightweight queue. Simple Queue.
    '''

    QUEUE_TYPE_NAME = 'simple'

    def __init__(self, id_args=[], collection_of=QUEUE_COLLECTION_OF_ELEMENTS,
                 keep_previous=True, redis_conn=None):
        '''
        Create a SimpleQueue object.

        Arguments:
        :id_args -- list, list's values will be used to name the queue
        :collection_of -- string (default: QUEUE_COLLECTION_OF_ELEMENTS),
                          a type descriptor of queued elements
        :keep_previous -- boolean (default: true),
                          a flag to create a fresh queue or not
        :redis_conn -- redis.client.Redis (default: None), a redis
                       connection will be created using the default
                       redis.client.Redis connection params.
        '''
        self.id_args = id_args
        self.collection_of = collection_of

        if redis_conn is None:
            redis_conn = redis.Redis()
        self.redis = redis_conn

        self.key_queue = self.get_key_queue()

        if keep_previous is False:
            self.delete()

    def __str__(self):
        '''
        Return a string representation of the class.

        Returns: string
        '''
        return '<SimpleQueue: %s (%s)>' % (self.key_queue, self.num())

    def get_key_queue(self):
        '''
        Get a key id that will be used to store/retrieve data from
        the redis server.

        Returns: string
        '''
        return 'queue:%s:type:%s:of:%s' % ('.'.join(self.id_args),
                                           SimpleQueue.QUEUE_TYPE_NAME,
                                           self.collection_of)

    def push(self, element, to_first=False):
        '''
        Push a element into the queue. Element can be pushed to the first or
        last position (by default is pushed to the last position).

        Arguments:
        :element -- string
        :to_first -- boolean (default: False)

        Raise:
        :PimPamQueuesElementWithoutValueError, if element has not a value

        Returns: long, the number of queued elements
        '''
        if element in ('', None):
            raise PimPamQueuesElementWithoutValueError()
        return self._push_to_queue(element, to_first)

    def push_some(self, elements, to_first=False, num_block_size=None):
        '''
        Push a bunch of elements into the queue. Elements can be pushed to the
        first or last position (by default are pushed to the last position).

        Arguments:
        :elements -- a collection of strings
        :to_first -- boolean (default: false)
        :num_block_size -- integer (default: none)

        Returns: long, the number of queued elements
        '''
        return self._push_some_to_queue(elements, to_first, num_block_size)

    def pop(self, last=False):
{'fraction_non_alphanumeric': 0.08143580012650221, 'fraction_numerical': 0.00031625553447185326, 'mean_word_length': 2.07935735150925, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1433983', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1702, 'n_words': 535}