def METHOD_NAME(self, tokensource, outfile):
    for ttype, value in tokensource:
        not_found = True
        while ttype and not_found:
            try:
                # outfile.write( "<" + str(ttype) + ">" )
                on, off = self.style_string[str(ttype)]
                # Like TerminalFormatter, add "reset colors" escape sequence
                # on newline.
                spl = value.split('\n')
                for line in spl[:-1]:
                    if line:
                        outfile.write(on + line + off)
                    outfile.write('\n')
                if spl[-1]:
                    outfile.write(on + spl[-1] + off)
                not_found = False
                # outfile.write( '#' + str(ttype) + '#' )
            except KeyError:
                # ottype = ttype
                ttype = ttype[:-1]
                # outfile.write( '!' + str(ottype) + '->' + str(ttype) + '!' )
        if not_found:
            outfile.write(value)