def _write_message(self, message, filename=None): if filename is None: filename = message.filename message_data = self._dump_message(message) file = open(filename + ".tmp", "wb") file.write(message_data) safe_close(file, safe=self.safe_file_closing) os.rename(filename + ".tmp", filename) #Strip the big data element and shove it in the cache temp_message = dict(message) if "data" in temp_message: temp_message["data"] = None self._message_cache[filename] = temp_message # For now we use the inode as the message id, as it will work # correctly even faced with holding/unholding. It will break # if the store is copied over for some reason, but this shouldn't # present an issue given the current uses. In the future we # should have a nice transactional storage (e.g. sqlite) which # will offer a more strong primary key. return os.stat(filename).st_ino
def _get_content(self, filename): file = open(filename, "rb") try: return file.read() finally: safe_close(file, safe=self.safe_file_closing)
def save(self, filepath, map): file = open(filepath, "wb") try: file.write(self._bpickle.dumps(map)) finally: safe_close(file, self.safe_file_closing)
def load(self, filepath): file = open(filepath, "rb") try: return self._bpickle.loads(file.read()) finally: safe_close(file, self.safe_file_closing)
def save(self, filepath, map): file = open(filepath, "wb") try: self._pickle.dump(map, file, 2) finally: safe_close(file, self.safe_file_closing)
def load(self, filepath): file = open(filepath) try: return self._pickle.load(file) finally: safe_close(file, self.safe_file_closing)