# Path: blitzdb/backends/file/store.py
# class TransactionalStore(Store):
# 
#     """
#     This class adds transaction support to the Store class.
#     """
# 
#     def __init__(self, properties):
#         super(TransactionalStore, self).__init__(properties)
#         self._enabled = True
#         self.begin()
# 
#     def begin(self):
#         self._delete_cache = set()
#         self._update_cache = {}
# 
#     def commit(self):
#         try:
#             self._enabled = False
#             for store_key in self._delete_cache:
#                 if super(TransactionalStore, self).has_blob(store_key):
#                     super(TransactionalStore, self).delete_blob(store_key)
#             for store_key, blob in self._update_cache.items():
#                 super(TransactionalStore, self).store_blob(blob, store_key)
#         finally:
#             self._enabled = True
# 
#     def has_blob(self, key):
#         if not self._enabled:
#             return super(TransactionalStore, self).has_blob(key)
#         if key in self._delete_cache:
#             return False
#         if key in self._update_cache:
#             return True
#         return super(TransactionalStore, self).has_blob(key)
# 
#     def get_blob(self, key):
#         if not self._enabled:
#             return super(TransactionalStore, self).get_blob(key)
#         if key in self._update_cache:
#             return self._update_cache[key]
#         return super(TransactionalStore, self).get_blob(key)
# 
#     def store_blob(self, blob, key, *args, **kwargs):
#         if not self._enabled:
#             return super(TransactionalStore, self).store_blob(blob, key, *args, **kwargs)
#         if key in self._delete_cache:
#             self._delete_cache.remove(key)
#         self._update_cache[key] = copy.copy(blob)
#         return key
# 
#     def delete_blob(self, key, *args, **kwargs):
#         if not self._enabled:
#             return super(TransactionalStore, self).delete_blob(key, *args, **kwargs)
#         if not self.has_blob(key):
#             raise KeyError("Key %s not found!" % key)
#         self._delete_cache.add(key)
#         if key in self._update_cache:
#             del self._update_cache[key]
# 
#     def rollback(self):
#         self._delete_cache = set()
#         self._update_cache = {}


import subprocess
import tempfile
import pytest
from blitzdb.backends.file import TransactionalStore




@pytest.fixture
def transactional_store():
    tmpdir = tempfile.mkdtemp()


# Path: blitzdb/backends/file/store.py
# class TransactionalStore(Store):
# 
#     """
#     This class adds transaction support to the Store class.
#     """
# 
#     def __init__(self, properties):
#         super(TransactionalStore, self).__init__(properties)
#         self._enabled = True
#         self.begin()
# 
#     def begin(self):
#         self._delete_cache = set()
#         self._update_cache = {}
# 
#     def commit(self):
#         try:
#             self._enabled = False
#             for store_key in self._delete_cache:
#                 if super(TransactionalStore, self).has_blob(store_key):
#                     super(TransactionalStore, self).delete_blob(store_key)
#             for store_key, blob in self._update_cache.items():
#                 super(TransactionalStore, self).store_blob(blob, store_key)
#         finally:
#             self._enabled = True
# 
#     def has_blob(self, key):
#         if not self._enabled:
#             return super(TransactionalStore, self).has_blob(key)
#         if key in self._delete_cache:
#             return False
#         if key in self._update_cache:
#             return True
#         return super(TransactionalStore, self).has_blob(key)
# 
#     def get_blob(self, key):
#         if not self._enabled:
#             return super(TransactionalStore, self).get_blob(key)
#         if key in self._update_cache:
#             return self._update_cache[key]
#         return super(TransactionalStore, self).get_blob(key)
# 
#     def store_blob(self, blob, key, *args, **kwargs):
#         if not self._enabled:
#             return super(TransactionalStore, self).store_blob(blob, key, *args, **kwargs)
#         if key in self._delete_cache:
#             self._delete_cache.remove(key)
#         self._update_cache[key] = copy.copy(blob)
#         return key
# 
#     def delete_blob(self, key, *args, **kwargs):
#         if not self._enabled:
#             return super(TransactionalStore, self).delete_blob(key, *args, **kwargs)
#         if not self.has_blob(key):
#             raise KeyError("Key %s not found!" % key)
#         self._delete_cache.add(key)
#         if key in self._update_cache:
#             del self._update_cache[key]
# 
#     def rollback(self):
#         self._delete_cache = set()
#         self._update_cache = {}


# Path: tests/test_file_stores.py
import subprocess
import tempfile
import pytest
from blitzdb.backends.file import TransactionalStore





@pytest.fixture
def transactional_store():
    tmpdir = tempfile.mkdtemp()


    yield TransactionalStore({'path': tmpdir})