def replace_booleans(line):
    """replaces postgres boolean literals with 0|1 within the values in an INSERT
    statement as created by pg_dump.

    .. note::

        - we rely on the INSERT statements not containing newlines.
        - we somewhat naively split the values at commas and assume that if a single
          token equals "true" or false", it was a boolean value in postgres. Obviously
          this assumption does not hold for a text value like "..., true, ...".
          We may switch to using sqlparse for a more robust detection of booleans.

    >>> assert replace_booleans('INSERT (true, false);').strip() == 'INSERT (1, 0);'
    """
    insert, values = line.split('(', 1)
    assert values.endswith(');')
    values = values[:-2]
    clean_values = []
    for token in values.split(', '):
        if token == 'true':
            token = "1"
        elif token == 'false':
            token = "0"
        clean_values.append(token)
    return '%s(%s);\n' % (insert, ', '.join(clean_values))