import tempfile


def create_symbol_redefinition_file(rename_symbols):
  """Create a helper file that will be used to redefine symbols.

  Args:
    rename_symbols: Dictionary of symbols to rename.
  Returns:
    NamedTemporaryFile object containing the helper data for redefining symbols,
    or None if there are no symbols to rename.
  """
  if not rename_symbols:
    return None
  # Write the symbol redefinition file. It will be cleaned up when the program
  # exits.
  redefinition_file = tempfile.NamedTemporaryFile()
  redefinition_data = open(redefinition_file.name, "w")
  any_written = False
  for key, val in rename_symbols.items():
    if key != val:
      any_written = True
      redefinition_data.write("%s %s\n" % (key, val))
  redefinition_data.close()
  return redefinition_file if any_written else None