Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def stash_mock():
with tempfile.NamedTemporaryFile() as fp:
fp.close()
with mock.patch.object(Stash, 'FILENAME', fp.name):
yield Stash()
def stash_mock():
with tempfile.NamedTemporaryFile() as fp:
fp.close()
with mock.patch.object(Stash, 'FILENAME', fp.name):
yield Stash()
def read(self):
with self.open() as db:
return dict(db)
def write(self, data):
with self.open() as db:
for key, value in data.items():
db[key] = value
@classmethod
def print_content(cls):
for key, value in cls().read().items():
print("{0}: {1}".format(key, value))
class LazyStash(Stash):
def __init__(self):
self._stashobj = None
@property
def _stash(self):
if self._stashobj is None:
self._stashobj = self.read()
return self._stashobj
def __getitem__(self, key):
return self._stash[key]
def get(self, key, default=None):
try:
return self._stash[key]
except KeyError:
def stash():
"""Print stash contents"""
from kibitzr.stash import Stash
Stash.print_content()