def load(self): try: print(('Loading %s' % self.filepath)) with open(self.filepath) as f: self.cache = pickle.load(f) except IOError: print('Cache file does not exist')
def __init__(self, *args, **kwargs): """ Parameters: leveled : bool / int Determines the folder hierarchy. False will create a flat hierarchy. Otherwise this value determines the depth. We are assuming the key is iterable which will determine the level values. Example: a key of ('HI', 1, 3) and leveled = 2 would create a file /cache_dir/HI/1/HI_1_3 Assuming that HI_1_3 is the filename """ super(MetaFileCache, self).__init__(*args, **kwargs) self.autosave = kwargs.pop('autosave', True) self.leveled = kwargs.pop('leveled', False) self._keys = {} # key -> filename self.keys_fn = self.get_filename('index', leveled=False) try: with open(self.keys_fn, 'rb') as f: keys = pickle.load(f) self._keys = keys except: pass
def load(path_or_buffer): if isinstance(path_or_buffer, str): f = open(str, 'rb') else: f = path_or_buffer try: return pickle.load(f) finally: f.close()
def _meta_dir(obj, meta=None): filepath = _meta_path(obj) if meta: with open(filepath, 'wb') as f: pickle.dump(meta, f) return try: with open(filepath, 'rb') as f: meta = pickle.load(f) return meta except: return {}
def _load_meta(name, path): with open(os.path.join(path, name), 'rb') as f: obj = pickle.load(f) return obj
def load(self): try: obj = pickle.load(self.get_fp()) self._dict = obj except: pass