コード例 #1
0
ファイル: manhole.py プロジェクト: levanhong05/MeshMagic
def lastColorizedLine(source):
    """Tokenize and colorize the given Python source.

    Returns a VT102-format colorized version of the last line of C{source}.
    """
    w = VT102Writer()
    p = TokenPrinter(w.write).printtoken
    s = StringIO.StringIO(source)

    tokenize.tokenize(s.readline, p)

    return str(w)
コード例 #2
0
ファイル: manhole.py プロジェクト: l0ganc/JD_Shop_spider
def lastColorizedLine(source):
    """
    Tokenize and colorize the given Python source.

    Returns a VT102-format colorized version of the last line of C{source}.

    @param source: Python source code
    @type source: L{str} or L{bytes}
    @return: L{bytes} of colorized source
    """
    if not isinstance(source, bytes):
        source = source.encode("utf-8")
    w = VT102Writer()
    p = TokenPrinter(w.write).printtoken
    s = BytesIO(source)

    for token in _tokenize(s.readline):
        (tokenType, string, start, end, line) = token
        p(tokenType, string, start, end, line)

    return bytes(w)