def __init__(self, dbname): try: import gdbm gdbm.open(dbname) self.__db = shelve.DbfilenameShelf(dbname) except: self.__db = shelve.open(dbname)
def __init__(self, path: Union[str, Path] = "/code/.cache/store.pkl"): self.path = Path(path) self.shelve = shelve.DbfilenameShelf( filename=str(self.path), flag="c", protocol=pickle.HIGHEST_PROTOCOL, writeback=True, )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._shelf = shelve.DbfilenameShelf( self.filename, flag="c", protocol=self.protocol, writeback=self.writeback, )
def __init__(self, storage_path: Union[Path, str], channel_from_id: Callable[[str], str], vod_path_template: str = '{id} {date:%Y-%m-%d}.ts') -> None: self.path = Path(storage_path) self.broadcast_template = vod_path_template self._channel_from_id = channel_from_id self._vod_ids: List[str] = [] self._create_storage_dir() self._db: shelve.DbfilenameShelf = shelve.DbfilenameShelf( str(self.path.joinpath(self.DB_FILENAME).resolve()))
def __init__(self, name='', max_concurrency=20): name = name or options.cache or "proxy_cache.db" self.name = name self.max_concurrency = max_concurrency self.entries = {} self.sem = threading.Semaphore(self.max_concurrency) self.semlock = threading.Lock() if options.clear_cache: flag = 'n' else: flag = 'c' self.db = shelve.DbfilenameShelf(name, flag)
def __init__(self, filename = ''): if filename: self.db = shelve.DbfilenameShelf(filename=filename, writeback=True) atexit.register(self.db.close) else: self.db = {} self.cache = {} if '_ids' not in self.db: self.db['_ids'] = {} self.ops_lut = {"==": (lambda x,y: x==type(x)(y)), "!=": (lambda x,y: x!=type(x)(y)), "<": (lambda x,y: x<type(x)(y)), ">": (lambda x, y: x > type(x)(y)), "<=": (lambda x, y: x <= type(x)(y)), ">=": (lambda x, y: x >= type(x)(y)), "~=": (lambda x, y: y.lower() in x.lower())}
def open(filename, flag='c'): """Open a persistent dictionary for reading and writing. Argument is the filename for the dirdbm database. Start using builtin shelve.DbfilenameShelf class as of Python 3. Note - flags to the anydbm.open() function mean: 'r' Open existing database for reading only (default) 'w' Open existing database for reading and writing 'c' Open db for read and write, creating if it doesn't exist 'n' Always create a new, empty db, open for reading and writing """ if PY3K: try: return shelve.DbfilenameShelf(filename, flag) except Exception, ex: # is dbm.error raise dirdbm.error(str(ex))
def __init__(self, options, templar, cache_file=None): """Handles the authentication against the API and calls the appropriate API endpoints. """ self._cache = None if cache_file is not None: self._cache = shelve.DbfilenameShelf(to_bytes(cache_file)) self._session_token = None self._options = options self._templar = templar self.cyberark_connection = self._options.get('cyberark_connection', dict()) self.cyberark_use_radius_authentication = ANSIBLE_CYBERARK_USE_RADIUS_AUTHENTICATION if 'cyberark_use_radius_authentication' in self.cyberark_connection: self.cyberark_use_radius_authentication = self.cyberark_connection[ 'cyberark_use_radius_authentication']
def main(): db = shelve.DbfilenameShelf('info.db') count = 0 for url in sys.argv[1:]: print url f = urllib2.urlopen(url) while True: line = f.readline() if not line: break line = line.strip() try: key, val = line.split(' => ', 1) except ValueError: continue db[key] = (InfoBot.locked, val) count += 1 print "Added %d facts." % count
def load_it(loadfile): log_info('LOAD: \"{0}\"'.format(loadfile)) global config global wl_dom global bl_dom global wl_ip4 global bl_ip4 global wl_ip6 global bl_ip6 global wl_big_rx global bl_big_rx global karma try: s = shelve.DbfilenameShelf(loadfile, flag='r', protocol=2) wl_dom = s['wl_dom'] bl_dom = s['bl_dom'] wl_ip4 = pytricia.PyTricia(32) from_dict(s['wl_ip4'], wl_ip4) bl_ip4 = pytricia.PyTricia(32) from_dict(s['bl_ip4'], bl_ip4) wl_ip6 = pytricia.PyTricia(128) from_dict(s['wl_ip6'], wl_ip6) bl_ip6 = pytricia.PyTricia(128) from_dict(s['bl_ip6'], bl_ip6) wl_big_rx = s['wl_big_rx'] bl_big_rx = s['bl_big_rx'] karma = s['karma'] s.close() except BaseException as err: log_err('SAVE-ERROR: Unable to open/read file \"{0}\" - {1}'.format(loadfile, err)) return False return True
def save_it(savefile): log_info('SAVE: \"{0}\"'.format(savefile)) try: s = shelve.DbfilenameShelf(savefile, flag='n', protocol=2) s.clear() s['wl_dom'] = wl_dom s['bl_dom'] = bl_dom s['wl_ip4'] = to_dict(wl_ip4) s['bl_ip4'] = to_dict(bl_ip4) s['wl_ip6'] = to_dict(wl_ip6) s['bl_ip6'] = to_dict(bl_ip6) s['wl_big_rx'] = wl_big_rx s['bl_big_rx'] = bl_big_rx s['karma'] = karma s.close() except BaseException as err: log_err('LOAD-ERROR: Unable to open/write file \"{0}\" - {1}'.format(savefile, err)) return False return True
def open_storage(self, path): if hasattr(self, 'shelf') and self.shelf is not None: raise StoreAlreadyOpenError("Storage appears to be opened already") log.debug("Opening storage file %s" % path) self.shelf = shelve.DbfilenameShelf(path, protocol=2) log.info('Opened shelf of %s at %s' % (self.__class__.__name__, path))
def __init__(self, *args, **kwargs): object.__setattr__( self, "_shelf", shelve.DbfilenameShelf(writeback=True, *args, **kwargs))
def __init__(self, filename): object.__setattr__(self, 'DICT', shelve.DbfilenameShelf(filename)) # cleaning the dict on the way out atexit.register(self._clean)
def open(self): self.cache = shelve.DbfilenameShelf(self.filename) return self
def activate(self): self.actived = True logging.info("Opening torrent database.") self.transmissionShelf = shelve.DbfilenameShelf(MAGNET_DB, protocol=-1) self.start_poller(10, self.do_announcement) super(Magnet, self).activate()
def __init__(self, path): log.debug('Open shelf storage %s' % path) self.shelf = shelve.DbfilenameShelf(path, protocol=2)
def open_storage(self, path): logging.info("Try to open db file %s" % path) self.shelf = shelve.DbfilenameShelf(path, protocol=2) logging.debug('Opened shelf of %s' % self.__class__.__name__)
last_allowed_time = datetime.datetime.now() - timeout self.db.delete(self.table, where="$last_allowed_time > atime", vars=locals()) class SessionExpired(Exception): pass # store = DiskStore('{0}/run/sessions'.format(os.getenv('TOMBOT_HOME'))) import shelve if not holder.session_store: holder.session_store = ShelfStore( shelve.DbfilenameShelf('{0}/run/session.db'.format(config.home), protocol=2)) class Session(object): """ Session implemention based on Room and User """ __slots__ = [ 'store', '_killed', '_data', 'session_id', '__getitem__', '__setitem__', '__delitem__', 'queue' ] def __init__(self, rid, uid): # web.py make it thread local, BUT, we must share it # self._data = utils.threadeddict() self._killed = False
import shelve from lxml.builder import E logging.basicConfig(level=logging.DEBUG,file=sys.stderr) logger=logging.getLogger(os.path.split(__file__)[1]) persid="37085" # url="http://api.littlesis.org/entity/%s/related/degree2.xml?cat1_ids=8&cat2_ids=8&num=100&page=%%i" % persid output="output/littlesis/lawrence_fink_%s_network_lobbying_%%04i.xml" % persid cache="data/littlesisids.db" idcache=shelve.DbfilenameShelf(cache) b=LittleSisBrowser() def id_to_url(ids) : if not ids in idcache : e=b.tree("http://api.littlesis.org/entity/%s.xml" % ids) logger.debug("%s -> %s" % (ids,e.xpath("//uri/text()")[0])) idcache[ids]=str(e.xpath("//uri/text()")[0]) return idcache[ids] page=1 while True : of=output % page iu=url % page
def __enter__(self): self._simulation_log = shelve.DbfilenameShelf(self._log_filename, protocol=2, writeback=False) return self