class_docstr: Format colored Python source.
      
class_docstr_tok: ["Format","colored","Python","source","."]
docstr: Parse and send the colored source.
  
  If out and scheme are not specified, the defaults (given to
  constructor) are used.
  
  out should be a file-type object. Optionally, out can be given as the
  string 'str' and the parser will automatically return the output in a
  string.
docstr_tok: ["Parse","and","send","the","colored","source",".","If","out","and","scheme","are","not","specified",",","the","defaults","(","given","to","constructor",")","are","used",".","out","should","be","a","file-type","object",".","Optionally",",","out","can","be","given","as","the","string","'str","'","and","the","parser","will","automatically","return","the","output","in","a","string","."]
code: def format2(self, raw, out=None):
      """Parse and send the colored source.
  
      If out and scheme are not specified, the defaults (given to
      constructor) are used.
  
      out should be a file-type object. Optionally, out can be given as the
      string 'str' and the parser will automatically return the output in a
      string."""
  
      string_output = 0
      if (
          out == "str"
          or self.out == "str"
          or isinstance(self.out, StringIO)
      ):
          # XXX - I don't really like this state handling logic, but at this
          # point I don't want to make major changes, so adding the
          # isinstance() check is the simplest I can do to ensure correct
          # behavior.
          out_old = self.out
          self.out = StringIO()
          string_output = 1
      elif out is not None:
          self.out = out
      else:
          raise ValueError(
              '`out` or `self.out` should be file-like or the value `"str"`'
          )
  
      # Fast return of the unmodified input for NoColor scheme
      if self.style == "NoColor":
          error = False
          self.out.write(raw)
          if string_output:
              return raw, error
          return None, error
  
      # local shorthands
      colors = self.color_table[self.style].colors
      self.colors = colors  # put in object so __call__ sees it
  
      # Remove trailing whitespace and normalize tabs
      self.raw = raw.expandtabs().rstrip()
  
      # store line offsets in self.lines
      self.lines = [0, 0]
      pos = 0
      raw_find = self.raw.find
      lines_append = self.lines.append
      while True:
          pos = raw_find("\n", pos) + 1
          if not pos:
              break
          lines_append(pos)
      lines_append(len(self.raw))
  
      # parse the source and write it
      self.pos = 0
      text = StringIO(self.raw)
  
      error = False
      try:
          for atoken in generate_tokens(text.readline):
              self(*atoken)
      except tokenize.TokenError as ex:
          msg = ex.args[0]
          line = ex.args[1][0]
          self.out.write(
              "%s\n\n*** ERROR: %s%s%s\n"
              % (
                  colors[token.ERRORTOKEN],
                  msg,
                  self.raw[self.lines[line] :],
                  colors.normal,
              )
          )
          error = True
      self.out.write(colors.normal + "\n")
      if string_output:
          output = self.out.getvalue()
          self.out = out_old
          return (output, error)
      return (None, error)
  
file_path: catboost/contrib/python/ipython/py3/IPython/utils/PyColorize.py
imports: import keyword
  import os
  import sys
  import token
  import tokenize
  from IPython.utils.coloransi import TermColors, InputTermColors, ColorScheme, ColorSchemeTable
  from .colorable import Colorable
  from io import StringIO
label_desc: Use image node_id 3 for calling the Parser obj's underlying member method code with example usage: obj.format2(raw, out) and returns: None,  error, None,  error, output,  error, raw,  error