コード例 #1
0
ファイル: Server.py プロジェクト: seanmead/PyJax
 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