def repr_with_newlines(string):
  """
  return the string, passed through repr(), but with
  newlines intact.

  Thus the string "new\nline" becomes not "new\\nline" but instead
  a string with a literal newline in it: '''new
line'''
  """

  # single-line string
  if '\n' not in string:
    return repr(string)

  # multiline string
  else:
    reprd = repr(string)

    # either ' or ", depending on how repr() decides to handle escapes
    quote_type = reprd[0]

    newlines_returned = reprd.replace('\\n', '\n')
    multiline_quotes = quote_type * 2 + newlines_returned + quote_type * 2
    return multiline_quotes