import textwrap


def _get_suite(buf, default, indent='  '):
  """This is a helper function to extract a python code suite from a StringIO
  object.

  This will dedent the buffer's content, split it into lines, and then re-indent
  it by the amount indicated.

  Args:
    * buf (StringIO) - The buffer to take the content from.
    * default (str) - The content to use if `buf` is empty.
    * indent (str) - The string to prepend to all de-indented lines.

  Returns the transformed string.
  """
  value = textwrap.dedent(buf.getvalue() or default).strip('\n')
  return '\n'.join(indent + l for l in value.splitlines())