'Token handler, with syntax highlighting.'

def __call__(self, toktype, toktext, start_pos, end_pos, line):

    (srow, scol) = start_pos
    (erow, ecol) = end_pos
    colors = self.colors
    owrite = self.out.write
    linesep = os.linesep
    oldpos = self.pos
    newpos = (self.lines[srow] + scol)
    self.pos = (newpos + len(toktext))
    if (newpos > oldpos):
        owrite(self.raw[oldpos:newpos])
    if (toktype in [token.INDENT, token.DEDENT]):
        self.pos = newpos
        return
    if (token.LPAR <= toktype <= token.OP):
        toktype = token.OP
    elif ((toktype == token.NAME) and keyword.iskeyword(toktext)):
        toktype = _KEYWORD
    color = colors.get(toktype, colors[_TEXT])
    if (linesep in toktext):
        toktext = toktext.replace(linesep, ('%s%s%s' % (colors.normal, linesep, color)))
    owrite(('%s%s%s' % (color, toktext, colors.normal)))
