def move_tmp(self, path, fail=False): """ Moves the tmp file to the specified path. :param path: directory to move the tmp file to :return: name of the file """ if self.__tmp: Event.print_events() Event.remove_event(key=self.__tmp) h = open(self.__tmp, 'rb') boundary = h.readline() filename = os.path.basename(Tools.get_item(h.readline(), 'filename')[1:-1]) content_type = h.readline().split(': ')[-1] blank_line = h.readline() if not filename or filename == '': return if os.path.exists(path + filename): if fail: return name, ext = Tools.split_extension(filename) filename = name + str(time.time()) + ext with open(path + filename, 'wb') as o: o.writelines(h.readlines()[:-1]) h.close() os.remove(self.__tmp) return filename
def __read_file(self, line, length): """ Reads the file that is uploaded into a temp directory. :param line: First line of the file :param length: Length of the content """ self.__tmp = Settings.Settings.WORKING_DIR + '/tmp/' + str(time.time()) with open(self.__tmp, 'wb') as o: o.write(line) max_int = 100000000 loop = length / max_int m = length % max_int for i in range(0, loop): with open(self.__tmp, 'ab') as o: o.write(self.rfile.read(max_int)) with open(self.__tmp, 'ab') as o: o.write(self.rfile.read(m)) Event.add_event(obj=File(self.__tmp), method='delete', interval=4, onetime=True, key=self.__tmp, start=True)