def touch(self, addr, lease=3600): is_valid = self.is_valid(addr) if not is_valid: raise netius.NetiusError("Not possible to touch address") current = time.time() target = int(current + lease) self.map[addr] = target heapq.heappush(self.addrs, (target, addr))
def get_file(self, key, mode="rb"): if not key in self.map: netius.NetiusError("Key not found") item = self.map[key] value = item["value"] file = netius.legacy.StringIO(value) close = self._build_close(file, key) file._close = file.close file.close = close return file
def peek(self): addr = None current = time.time() while True: target, addr = heapq.heappop(self.addrs) _target = self.map.get(addr, 0) if not target == _target: continue if target > current: heapq.heappush(self.addrs, (target, addr)) raise netius.NetiusError("No address available") break return addr