def canonicalize_eol(text, eol):
  """Replace any end-of-line sequences in TEXT with the string EOL."""

  text = text.replace('\r\n', '\n')
  text = text.replace('\r', '\n')
  if eol != '\n':
    text = text.replace('\n', eol)
  return text