# 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
class UUIDDecorator(StoreDecorator):
    """UUID generating decorator

    Overrides :meth:`.KeyValueStore.put` and :meth:`.KeyValueStore.put_file`.
    If a key of *None* is passed, a new UUID will be generated as the key. The
    attribute `uuidfunc` determines which UUID-function to use and defaults to
    'uuid1'.

    .. note::
       There seems to be a bug in the uuid module that prevents initializing
       `uuidfunc` too early. For that reason, it is a string that will be
       looked up using :func:`getattr` on the :mod:`uuid` module.
    """
    # for strange reasons, this needs to be looked up as late as possible
    uuidfunc = 'uuid1'

    def __init__(self, store, template=u'{}'):
        super(UUIDDecorator, self).__init__(store)
        self._template = template

    def put(self, key, data, *args, **kwargs):
        if not key:
            key = text_type(getattr(uuid, self.uuidfunc)())

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

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

# 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

class UUIDDecorator(StoreDecorator):
    """UUID generating decorator

    Overrides :meth:`.KeyValueStore.put` and :meth:`.KeyValueStore.put_file`.
    If a key of *None* is passed, a new UUID will be generated as the key. The
    attribute `uuidfunc` determines which UUID-function to use and defaults to
    'uuid1'.

    .. note::
       There seems to be a bug in the uuid module that prevents initializing
       `uuidfunc` too early. For that reason, it is a string that will be
       looked up using :func:`getattr` on the :mod:`uuid` module.
    """
    # for strange reasons, this needs to be looked up as late as possible
    uuidfunc = 'uuid1'

    def __init__(self, store, template=u'{}'):
        super(UUIDDecorator, self).__init__(store)
        self._template = template

    def put(self, key, data, *args, **kwargs):
        if not key:
            key = text_type(getattr(uuid, self.uuidfunc)())

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

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

            key = text_type(getattr(uuid, self.uuidfunc)())