def tidy_html(html):
    """
    Process an input string containing HTML and return a tuple (xhtml,
    errors, warnings) containing the output of tidylib and lists of
    validation errors and warnings.

    Input must be unicode.
    Output will be valid XHTML.
    """
    if not isinstance(html, six.text_type):
        raise ValueError("tidyhtml must be called with a Unicode string!")

    errors = list()
    warnings = list()

    # First, deal with embedded control codes:
    html, sub_count = CONTROL_CHAR_RE.subn(" ", html)
    if sub_count:
        warnings.append("Stripped %d control characters from body: %s" % (
            sub_count,
            set(ord(i) for i in CONTROL_CHAR_RE.findall(html))
        ))

    # tidylib.tidy_fragment will choke if given a full HTML document. This is a
    # primitive content sniff to decide whether to call tidy_document instead:
    if "<html" in html[:1024]:
        tidy_f = tidylib.tidy_document
        doc_mode = True
    else:
        tidy_f = tidylib.tidy_fragment
        doc_mode = False

    html, messages = tidy_f(html.strip(), {
        "char-encoding": "utf8",
        "clean": False,
        "drop-empty-paras": False,
        "drop-font-tags": True,
        "drop-proprietary-attributes": False,
        "fix-backslash": True,
        "indent": True,
        "output-xhtml": True,
    }
    )

    messages = filter(None, (l.strip() for l in messages.split("\n") if l))

    # postprocess warnings to avoid HTML fragments being reported as lacking
    # doctype and title:
    for msg in messages:
        if not doc_mode and msg in "Warning: missing <!DOCTYPE> declaration":
            continue
        if (not doc_mode
                and "Warning: inserting missing 'title' element" in msg):
            continue
        if not doc_mode and "Warning: inserting implicit <body>" in msg:
            continue

        if "Error:" in msg:
            errors.append(msg)
        else:
            warnings.append(msg)

    return html, errors, warnings
dataset/ETHPy150Open feincms/feincms/feincms/utils/html/tidy.py/tidy_html/swapped operands of `in`