def set(self, key, data): md5 = '%s' % make_md5(self.V, key) filename = path.join(self.directory, md5) fd, temp_filename = tempfile.mkstemp(prefix='.' + md5, dir=self.directory) try: with os.fdopen(fd, 'wb') as f: pickle.dump(data, f) f.flush() os.rename(temp_filename, filename) except: os.unlink(temp_filename) raise
def set(self, key, data): md5 = '%s' % make_md5(self.V, key) filename = path.join(self.directory, md5) temp_filename = path.join(self.directory, os.urandom(16).encode('hex')) fd = self._touch(temp_filename) try: with os.fdopen(fd, 'wb') as f: pickle.dump(data, f) f.flush() if os.path.isfile(filename): os.unlink(filename) os.rename(temp_filename, filename) except: os.unlink(temp_filename) raise
def set(self, key, data): md5 = '%s' % make_md5(self.V, key) filename = path.join(self.directory, md5) fd, temp_filename = tempfile.mkstemp(prefix='.' + md5, dir=self.directory) try: with os.fdopen(fd, 'wb') as f: pickle.dump(data, f) f.flush() # If a non default mode is specified, then chmod the file to # it before renaming it into place if self.new_file_mode is not None: os.chmod(temp_filename, self.new_file_mode) if os.path.isfile(filename): os.unlink(filename) os.rename(temp_filename, filename) except: os.unlink(temp_filename) raise
def set(self, key, data): md5 = '%s' % make_md5(self.V, key) filename = path.join(self.directory, md5) temp_filename = path.join(self.directory, os.urandom(16).encode('hex')) fd = self._touch(temp_filename) try: with os.fdopen(fd, 'wb') as f: pickle.dump(data, f) f.flush() # If a non default mode is specified, then chmod the file to # it before renaming it into place if self.new_file_mode is not None: os.chmod(temp_filename, self.new_file_mode) if os.path.isfile(filename): os.unlink(filename) os.rename(temp_filename, filename) except: os.unlink(temp_filename) raise
def set(self, key, data): now = time.time() md5 = '%s' % make_md5(self.V, key) self.cache[md5] = (data, now + 600) directory = self.directory filename = os.path.join(directory, md5) try: fd, temp_filename = tempfile.mkstemp(prefix='.' + md5, dir=directory) except OSError: if not os.path.exists(directory): os.makedirs(directory) fd, temp_filename = tempfile.mkstemp(prefix='.' + md5, dir=directory) try: with os.fdopen(fd, 'wb') as f: pickle.dump(data, f) f.flush() os.rename(temp_filename, filename) except: os.unlink(temp_filename) raise