def write_stream (stream, holders, defaultsection=None):
    """Very simple writing in ini format. The simple stringification of each value
    in each Holder is printed, and no escaping is performed. (This is most
    relevant for multiline values or ones containing pound signs.) `None` values are
    skipped.

    Arguments:

    stream
      A text stream to write to.
    holders
      An iterable of objects to write. Their fields will be
      written as sections.
    defaultsection=None
      Section name to use if a holder doesn't contain a
      `section` field.

    """
    anybefore = False

    for h in holders:
        if anybefore:
            print ('', file=stream)

        s = h.get ('section', defaultsection)
        if s is None:
            raise ValueError ('cannot determine section name for item <%s>' % h)
        print ('[%s]' % s, file=stream)

        for k in sorted (x for x in six.iterkeys (h.__dict__) if x != 'section'):
            v = h.get (k)
            if v is None:
                continue

            print ('%s = %s' % (k, v), file=stream)

        anybefore = True
Very simple writing in ini format. The simple stringification of each value
    in each Holder is printed, and no escaping is performed. (This is most
    relevant for multiline values or ones containing pound signs.) `None` values are
    skipped.

    Arguments:

    stream
      A text stream to write to.
    holders
      An iterable of objects to write. Their fields will be
      written as sections.
    defaultsection=None
      Section name to use if a holder doesn't contain a
      `section` field.