How to use the kibitzr.stash.Stash function in kibitzr

To help you get started, we’ve selected a few kibitzr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kibitzr / kibitzr / tests / helpers.py View on Github external
def stash_mock():
    with tempfile.NamedTemporaryFile() as fp:
        fp.close()
        with mock.patch.object(Stash, 'FILENAME', fp.name):
            yield Stash()
github kibitzr / kibitzr / tests / helpers.py View on Github external
def stash_mock():
    with tempfile.NamedTemporaryFile() as fp:
        fp.close()
        with mock.patch.object(Stash, 'FILENAME', fp.name):
            yield Stash()
github kibitzr / kibitzr / kibitzr / stash.py View on Github external
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:
github kibitzr / kibitzr / kibitzr / cli.py View on Github external
def stash():
    """Print stash contents"""
    from kibitzr.stash import Stash
    Stash.print_content()