def METHOD_NAME(self, tokensource, outfile):
    # hack: if the output is a terminal and has an encoding set,
    # use that to avoid unicode encode problems
    if not self.encoding and hasattr(outfile, "encoding") and \
       hasattr(outfile, "isatty") and outfile.isatty() and \
       sys.version_info < (3,):
        self.encoding = outfile.encoding
    return Formatter.METHOD_NAME(self, tokensource, outfile)