def cachedir(self, dirpath=None): """ get or set the cache file directory path :param dirpath: str or None, cache file directory path :return: str or None """ if dirpath is not None: # make directory if not exist if not os.path.exists(dirpath): os.makedirs(dirpath) self._cachedir = dirpath # open new dbm cachefile = self._cachedir + "/" + self._name self._dbm = _gdbm.open(cachefile, 'c') else: return self._cachedir
def __init__(self, name=_default_cache_name, dirpath=_default_cache_dir): """ initialize file cache with cache file path :param name: str, cache name :param dirpath: str, cache directory path """ if name is None: name = self._default_cache_dir if dirpath is None: dirpath = self._default_cache_dir cachedir = self._default_cache_dir if not os.path.exists(cachedir): os.makedirs(cachedir) self._name = name cachefile = self._default_cache_dir + "/" + name self._dbm = _gdbm.open(cachefile, 'c')
def shelve_open_gdbm(filename, flag='c', protocol=None, writeback=False): import _gdbm return shelve.Shelf(_gdbm.open(filename, flag), protocol, writeback)
def shelve_open_gdbm(filename, flag='c', protocol=None, writeback=False): import _gdbm # pylint: disable=import-error return shelve.Shelf(_gdbm.open(filename, flag), protocol, writeback)
def gdbm_shelve(filename, flag="c"): return shelve.Shelf(_gdbm.open(filename, flag))
from ._util import PY2, first if PY2: import anydbm error = first(anydbm.error) else: import dbm import _dbm try: import _gdbm except ImportError: _gdbm = None error = first(dbm.error) try: tmpdir = tempfile.mkdtemp() ndbm = type(_dbm.open(os.path.join(tmpdir, 'ndbm'), 'n')) if _gdbm is not None: gdbm = type(_gdbm.open(os.path.join(tmpdir, 'gdbm'), 'n')) finally: shutil.rmtree(tmpdir, True) del tmpdir