# Path: simplekv/decorator.py
# class StoreDecorator(object):
#     """Base class for store decorators.
# 
#     The default implementation will use :func:`getattr` to pass through all
#     attribute/method requests to an underlying object stored as
#     :attr:`_dstore`. It will also pass through the :attr:`__getattr__` and
#     :attr:`__contains__` python special methods.
#     """
# 
#     def __init__(self, store):
#         self._dstore = store
# 
#     def __getattr__(self, attr):
#         store = object.__getattribute__(self, "_dstore")
#         return getattr(store, attr)
# 
#     def __contains__(self, *args, **kwargs):
#         return self._dstore.__contains__(*args, **kwargs)
# 
#     def __iter__(self, *args, **kwargs):
#         return self._dstore.__iter__(*args, **kwargs)
# 
# Path: simplekv/_compat.py
# PY2 = sys.version_info[0] == 2


import hashlib
import os
import tempfile
import uuid
from .decorator import StoreDecorator
from ._compat import text_type
>>>
>>> store = HashDecorator(DictStore())
>>>
>>> key = store.put(None, b'my_data') #  note the passing of 'None' as key
>>> print(key)
ab0c15b6029fdffce16b393f2d27ca839a76249e
"""




class HashDecorator(StoreDecorator):
    """Hash function decorator

    Overrides :meth:`.KeyValueStore.put` and :meth:`.KeyValueStore.put_file`.
    If a key of *None* is passed, the data/file is hashed using
    ``hashfunc``, which defaults to *hashlib.sha1*. """

    def __init__(self, decorated_store, hashfunc=hashlib.sha1, template=u'{}'):
        self.hashfunc = hashfunc
        self._template = template
        super(HashDecorator, self).__init__(decorated_store)

    def put(self, key, data, *args, **kwargs):
        if not key:
            key = self._template.format(self.hashfunc(data).hexdigest())

        return self._dstore.put(key, data, *args, **kwargs)

    def put_file(self, key, file, *args, **kwargs):

# Path: simplekv/decorator.py
# class StoreDecorator(object):
#     """Base class for store decorators.
# 
#     The default implementation will use :func:`getattr` to pass through all
#     attribute/method requests to an underlying object stored as
#     :attr:`_dstore`. It will also pass through the :attr:`__getattr__` and
#     :attr:`__contains__` python special methods.
#     """
# 
#     def __init__(self, store):
#         self._dstore = store
# 
#     def __getattr__(self, attr):
#         store = object.__getattribute__(self, "_dstore")
#         return getattr(store, attr)
# 
#     def __contains__(self, *args, **kwargs):
#         return self._dstore.__contains__(*args, **kwargs)
# 
#     def __iter__(self, *args, **kwargs):
#         return self._dstore.__iter__(*args, **kwargs)
# 
# Path: simplekv/_compat.py
# PY2 = sys.version_info[0] == 2


# Path: simplekv/idgen.py
import hashlib
import os
import tempfile
import uuid
from .decorator import StoreDecorator
from ._compat import text_type

>>>
>>> store = HashDecorator(DictStore())
>>>
>>> key = store.put(None, b'my_data') #  note the passing of 'None' as key
>>> print(key)
ab0c15b6029fdffce16b393f2d27ca839a76249e
"""




class HashDecorator(StoreDecorator):
    """Hash function decorator

    Overrides :meth:`.KeyValueStore.put` and :meth:`.KeyValueStore.put_file`.
    If a key of *None* is passed, the data/file is hashed using
    ``hashfunc``, which defaults to *hashlib.sha1*. """

    def __init__(self, decorated_store, hashfunc=hashlib.sha1, template=u'{}'):
        self.hashfunc = hashfunc
        self._template = template
        super(HashDecorator, self).__init__(decorated_store)

    def put(self, key, data, *args, **kwargs):
        if not key:
            key = self._template.format(self.hashfunc(data).hexdigest())

        return self._dstore.put(key, data, *args, **kwargs)

    def put_file(self, key, file, *args, **kwargs):

        bufsize = 1024 * 1024