<commit_before>"""
Stores jobs in a MongoDB database.
"""
from bson.binary import Binary

from apscheduler.jobstores.base import JobStore
from apscheduler.job import Job
from apscheduler.util import obj_to_ref

try:
    import cPickle as pickle
except ImportError:
    import pickle

try:
    from cStringIO import StringIO
except ImportError:
    try:
        from io import StringIO
    except ImportError:
        from StringIO import StringIO

try:
    from pymongo.connection import Connection
except ImportError:
    raise ImportError('MongoDBJobStore requires PyMongo installed')


class MongoDBJobStore(JobStore):
    PICKLE_PROTOCOL = pickle.HIGHEST_PROTOCOL

    def __init__(self, database='apscheduler', collection='jobs',
                 connection=None, pickle_protocol=pickle.HIGHEST_PROTOCOL,
                 **connect_args):
        self.jobs = []
        self.pickle_protocol = pickle_protocol

        if connection:
            self._connection = connection
        else:
            self._connection = None
            self._connect_args = connect_args

        if not database:
            raise ValueError('The "database" parameter must not be empty')
        if not collection:
            raise ValueError('The "collection" parameter must not be empty')

        self._dbname = database
        self._collname = collection
        self._collection = None

    @property
    def collection(self):
        if (not self._collection or not
            self._collection.database.connection.host):
            if not self._connection:
                self._connection = Connection(**self._connect_args)
            self._collection = self._connection[self._dbname][self._collname]
<commit_msg>Removed an unused import (StringIO) and an unused constant (PICKLE_PROTOCOL)<commit_after>"""
Stores jobs in a MongoDB database.
"""
from bson.binary import Binary

from apscheduler.jobstores.base import JobStore
from apscheduler.job import Job
from apscheduler.util import obj_to_ref

try:
    import cPickle as pickle
except ImportError:
    import pickle

try:
    from pymongo.connection import Connection
except ImportError:
    raise ImportError('MongoDBJobStore requires PyMongo installed')


class MongoDBJobStore(JobStore):
    def __init__(self, database='apscheduler', collection='jobs',
                 connection=None, pickle_protocol=pickle.HIGHEST_PROTOCOL,
                 **connect_args):
        self.jobs = []
        self.pickle_protocol = pickle_protocol

        if connection:
            self._connection = connection
        else:
            self._connection = None
            self._connect_args = connect_args

        if not database:
            raise ValueError('The "database" parameter must not be empty')
        if not collection:
            raise ValueError('The "collection" parameter must not be empty')

        self._dbname = database
        self._collname = collection
        self._collection = None

    @property
    def collection(self):
        if (not self._collection or not
            self._collection.database.connection.host):
            if not self._connection:
                self._connection = Connection(**self._connect_args)
            self._collection = self._connection[self._dbname][self._collname]

{'fraction_non_alphanumeric': 0.0701219512195122, 'fraction_numerical': 0.0, 'mean_word_length': 2.6865168539325843, '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': '1870138', 'n_tokens_mistral': 866, 'n_tokens_neox': 852, 'n_words': 247}