code: def get_temporary_file(prefix="tmp_",
                         suffix="",
                         directory=None):
      
      try:
          file_fd, filepath = mkstemp(prefix=prefix,
                                      suffix=suffix,
                                      dir=directory)
          os.close(file_fd)
      except IOError, e:
          try:
              os.remove(filepath)
          except Exception:
              pass
          raise e
      return filepath
docs: Generate a safe and closed filepath.