import ast


def black_repr(text):
    """Format some Chars as Source Chars, in the Black Style of Python"""

    if text is None:

        return None

    assert text == str(text), repr(text)

    # Glance over the oneline Repr from Python

    repped = repr(text)

    q1 = repped[0]
    q2 = repped[-1]
    middle_repped = repped[1:][:-1]

    assert q1 == q2, (q1, q2)
    assert q1 in ("'", '"'), repr(q1)

    # Choose the Start Mark and End Mark from:  " ' r" r'

    q = '"' if ('"' not in middle_repped) else q1
    pychars = q + middle_repped + q

    if ("\\" in text) and not text.endswith("\\"):
        if '"' not in text:
            pychars = 'r"{}"'.format(text)
        elif "'" not in text:
            pychars = "r'{}'".format(text)

    # Require correct Eval

    evalled = ast.literal_eval(pychars)
    assert evalled == text, (text, pychars, evalled)

    return pychars