<commit_before>from __future__ import absolute_import, division, print_function

import json
from abc import ABCMeta, abstractmethod
from datetime import datetime

import six
from dateutil.parser import parse
from represent import RepresentationMixin

from bucketcache.config import *
from bucketcache.exceptions import *
from bucketcache.utilities import _raise_invalid_keys, _raise_keys

from .abc import abstractclassmethod


try:
    import cPickle as pickle
except ImportError:
    import pickle

try:
    import msgpack
    msgpack_available = True
except ImportError:
    msgpack_available = False

__all__ = [
    'PickleBackend',
    'JSONBackend',
    'MessagePackBackend',
]


class Backend(RepresentationMixin, object):
    __metaclass__ = ABCMeta
    abstract_attributes = {'binary_format', 'default_config', 'file_extension'}

    def __init__(self, value, expiration_date=None, config=None):
        self.value = value
        self.expiration_date = expiration_date
        self.config = self.valid_config(config)

        for attr in Backend.abstract_attributes:
            if not hasattr(self.__class__, attr):
                raise TypeError('Concrete class {} missing abstract attribute:'
                                ' {}'.format(self.__class__.__name__, attr))

        super(Backend, self).__init__()

    @classmethod
    def check_concrete(cls):
        """Very that we're a concrete class.

        Check that abstract methods have been overridden, and verify that
        abstract class attributes exist.

        Although ABCMeta checks the abstract methods on instantiation, we can
        also do this here to ensure the given Backend is valid when the Bucket
        is created.
        """
        if cls.__abstractmethods__:
            _raise_keys(cls.__abstractmethods__, "Concrete class '{}' missing "
                        "abstract method{{s}}: {{keys}}".format(cls.__name__))

        missing = {name
                   for name in Backend.abstract_attributes<commit_msg>Use six.add_metaclass for py 2 and 3 compatiblity<commit_after>from __future__ import absolute_import, division, print_function

import json
from abc import ABCMeta, abstractmethod
from datetime import datetime

import six
from dateutil.parser import parse
from represent import RepresentationMixin

from bucketcache.config import *
from bucketcache.exceptions import *
from bucketcache.utilities import _raise_invalid_keys, _raise_keys

from .abc import abstractclassmethod


try:
    import cPickle as pickle
except ImportError:
    import pickle

try:
    import msgpack
    msgpack_available = True
except ImportError:
    msgpack_available = False

__all__ = [
    'PickleBackend',
    'JSONBackend',
    'MessagePackBackend',
]


@six.add_metaclass(ABCMeta)
class Backend(RepresentationMixin, object):
    abstract_attributes = {'binary_format', 'default_config', 'file_extension'}

    def __init__(self, value, expiration_date=None, config=None):
        self.value = value
        self.expiration_date = expiration_date
        self.config = self.valid_config(config)

        for attr in Backend.abstract_attributes:
            if not hasattr(self.__class__, attr):
                raise TypeError('Concrete class {} missing abstract attribute:'
                                ' {}'.format(self.__class__.__name__, attr))

        super(Backend, self).__init__()

    @classmethod
    def check_concrete(cls):
        """Very that we're a concrete class.

        Check that abstract methods have been overridden, and verify that
        abstract class attributes exist.

        Although ABCMeta checks the abstract methods on instantiation, we can
        also do this here to ensure the given Backend is valid when the Bucket
        is created.
        """
        if cls.__abstractmethods__:
            _raise_keys(cls.__abstractmethods__, "Concrete class '{}' missing "
                        "abstract method{{s}}: {{keys}}".format(cls.__name__))

        missing = {name
                   for name in Backend.abstract_attributes
{'fraction_non_alphanumeric': 0.07033939990162322, 'fraction_numerical': 0.0004918839153959665, 'mean_word_length': 3.0347222222222223, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4190940', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1048, 'n_words': 337}