def gather_pieces(fmtstr, placeholder):
    """
    Takes a format string where % marks replacements by placeholder, and %%
    marks replacements by %. The returned object is a list of substrings and
    placeholders.
    """
    pieces = []
    substr = []
    escape = False
    for c in fmtstr:
        if escape:
            if c == '%':
                substr.append(c)
            else:
                pieces.append(''.join(substr))
                substr = []
                pieces.append(placeholder)
                substr.append(c)
            escape = False
        else:
            if c == '%':
                escape = True
            else:
                substr.append(c)
    pieces.append(''.join(substr))
    if escape:
        pieces.append(placeholder)
    return pieces