How to use the tinydb.Storage function in tinydb

To help you get started, we’ve selected a few tinydb 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 marcwebbie / passpie / passpie / database.py View on Github external
from datetime import datetime
import logging
import os
import shutil

from tinydb import TinyDB, Storage, where, Query
import yaml

from .utils import mkdir_open
from .history import Repository
from .credential import split_fullname, make_fullname


class PasspieStorage(Storage):
    extension = ".pass"

    def __init__(self, path):
        super(PasspieStorage, self).__init__()
        self.path = path

    def make_credpath(self, name, login):
        dirname, filename = name, login + self.extension
        credpath = os.path.join(self.path, dirname, filename)
        return credpath

    def delete(self, credentials):
        for cred in credentials:
            credpath = self.make_credpath(cred["name"], cred["login"])
            os.remove(credpath)
            if not os.listdir(os.path.dirname(credpath)):
github VirgilSecurity / virgil-iotkit / tools / key-management / virgil_keymanager / storage / tinydb_storage_extensions / signed_storage.py View on Github external
import base64
import json
import os
import binascii

import sys

from PyCRC.CRCCCITT import CRCCCITT
from tinydb import Storage
from tinydb.storages import touch

from virgil_keymanager.consts import VSKeyTypeS


class SignedByteStorage(Storage):
    """
    Store the data in a hexlified pickled bytes file with signatures of Auth and TL Service keys.
    """

    def __init__(self, path, create_dirs=False, **kwargs):
        """
        Create a new instance.

        Also creates the storage file, if it doesn't exist.

        :param path: Where to store the JSON data.
        :type path: str
        """

        super(SignedByteStorage, self).__init__()
        touch(path, create_dirs=create_dirs)  # Create file if not exists
github VirgilSecurity / virgil-iotkit / tools / key-management / virgil_keymanager / storage / tinydb_storage_extensions / byte_storage.py View on Github external
import json
import os
import binascii

from tinydb import Storage
from tinydb.storages import touch


class ByteStorage(Storage):
    """
    Store the data in a hexlified pickled bytes file.
    """

    def __init__(self, path, create_dirs=False, **kwargs):
        """
        Create a new instance.

        Also creates the storage file, if it doesn't exist.

        :param path: Where to store the JSON data.
        :type path: str
        """

        super(ByteStorage, self).__init__()
        self._suppress_db_warning = kwargs.pop("suppress_db_warning") or False