# 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
                    return self._dstore.put_file(
                        self._template.format(phash.hexdigest()),
                        file, *args, **kwargs)
            else:
                tmpfile = tempfile.NamedTemporaryFile(delete=False)
                try:
                    while True:
                        buf = file.read(bufsize)
                        phash.update(buf)
                        tmpfile.write(buf)

                        if len(buf) < bufsize:
                            break

                    tmpfile.close()
                    return self._dstore.put_file(
                        self._template.format(phash.hexdigest()),
                        tmpfile.name, *args, **kwargs
                    )
                finally:
                    try:
                        os.unlink(tmpfile.name)
                    except OSError as e:
                        if 2 == e.errno:
                            pass  # file already gone
                        else:
                            raise
        return self._dstore.put_file(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

                    return self._dstore.put_file(
                        self._template.format(phash.hexdigest()),
                        file, *args, **kwargs)
            else:
                tmpfile = tempfile.NamedTemporaryFile(delete=False)
                try:
                    while True:
                        buf = file.read(bufsize)
                        phash.update(buf)
                        tmpfile.write(buf)

                        if len(buf) < bufsize:
                            break

                    tmpfile.close()
                    return self._dstore.put_file(
                        self._template.format(phash.hexdigest()),
                        tmpfile.name, *args, **kwargs
                    )
                finally:
                    try:
                        os.unlink(tmpfile.name)
                    except OSError as e:
                        if 2 == e.errno:
                            pass  # file already gone
                        else:
                            raise
        return self._dstore.put_file(key, file, *args, **kwargs)



class UUIDDecorator(StoreDecorator):