def METHOD_NAME(generator, id_whitespace_replacement,
                               description_newline_replacement, require_qual,
                               lowercase=None):
    if ((id_whitespace_replacement is not None and
         '\n' in id_whitespace_replacement) or
        (description_newline_replacement is not None and
         '\n' in description_newline_replacement)):
        raise ValueError(
            "Newline character (\\n) cannot be used to replace whitespace in "
            "sequence IDs, nor to replace newlines in sequence descriptions.")
    for idx, seq in enumerate(generator):
        if len(seq) < 1:
            raise ValueError(
                "%s sequence does not contain any characters (i.e., it is an "
                "empty/blank sequence). Writing empty sequences is not "
                "supported." % cardinal_to_ordinal(idx + 1))
        if 'id' in seq.metadata:
            id_ = '%s' % seq.metadata['id']
        else:
            id_ = ''
        if id_whitespace_replacement is not None:
            id_ = _whitespace_regex.sub(id_whitespace_replacement, id_)
        if 'description' in seq.metadata:
            desc = '%s' % seq.metadata['description']
        else:
            desc = ''
        if description_newline_replacement is not None:
            desc = _newline_regex.sub(description_newline_replacement, desc)
        if desc:
            header = '%s %s' % (id_, desc)
        else:
            header = id_
        if require_qual and 'quality' not in seq.positional_metadata:
            raise ValueError(
                "Cannot write %s sequence because it does not have quality "
                "scores associated with it." % cardinal_to_ordinal(idx + 1))
        qual = None
        if 'quality' in seq.positional_metadata:
            qual = seq.positional_metadata['quality'].values
        if lowercase is not None:
            seq_str = seq.lowercase(lowercase)
        else:
            seq_str = str(seq)
        yield header, "%s" % seq_str, qual