def load(self): log.msg(self, 'load') if os.path.exists(self.file): # Load with open(self.file, 'rb') as fp: next, data = mload(fp) log.msg(self, 'load', len(data)) self.next = self.counter(next) self.data = dict(((group['id'], Group.fromDict(group)) for group in data)) log.msg(self, 'load ok')
def load(self): log.msg(self, 'load') if os.path.exists(self.file): # Load with open(self.file, 'rb') as fp: next, data = mload(fp) log.msg(self, 'load', len(data)) self.next = self.counter(next) self.data = dict(((message['id'], Message.fromDict(message)) for message in data)) log.msg(self, 'load ok')
def load(self): log.msg(self, 'load') if os.path.exists(self.file): # Load with open(self.file, 'rb') as fp: next, data = mload(fp) log.msg(self, 'load', len(data[0]), len(data[1]), len(data[2])) self.next = self.counter(next) self.data = (( deque(tuple(To.fromDict(to) for to in data[0])), [(priority, To.fromDict(to)) for priority, to in data[1]], [(after, To.fromDict(to)) for after, to in data[2]], )) # Transform list into a heap heapify(self.data[1]) heapify(self.data[2]) log.msg(self, 'load ok')
def get(self, name): if self.id is None: raise RuntimeError('Cannot get with ID none') if self._cachedLife: # Try find in cache result = self._cachedGet(name) if not result is self._cachedNone: # Success return result path, file = self.path(name) if os.path.exists(file): with open(file, 'rb') as fp: result = mload(fp) # If cache enabled, set it if self._cachedLife: self._cachedSet(name, result) # Return to user, not from cache return result