parameters: (tokens, formatter, outfile=None)
docstring: Format a tokenlist ``tokens`` with the formatter ``formatter``.
  
      If ``outfile`` is given and a valid file object (an object
      with a ``write`` method), the result will be written to it, otherwise
      it is returned as a string.
docstring_summary: Format a tokenlist ``tokens`` with the formatter ``formatter``.
docstring_tokens: Format a tokenlist tokens with the formatter formatter .
function: def format(tokens, formatter, outfile=None):
      """
      Format a tokenlist ``tokens`` with the formatter ``formatter``.
  
      If ``outfile`` is given and a valid file object (an object
      with a ``write`` method), the result will be written to it, otherwise
      it is returned as a string.
      """
      try:
          if not outfile:
              #print formatter, 'using', formatter.encoding
              realoutfile = formatter.encoding and BytesIO() or StringIO()
              formatter.format(tokens, realoutfile)
              return realoutfile.getvalue()
          else:
              formatter.format(tokens, outfile)
      except TypeError, err:
          if isinstance(err.args[0], str) and \
             'unbound method format' in err.args[0]:
              raise TypeError('format() argument must be a formatter instance, '
                              'not a class')
          raise
function_tokens: def format ( tokens , formatter , outfile = None ) : try : if not outfile : #print formatter, 'using', formatter.encoding realoutfile = formatter . encoding and BytesIO ( ) or StringIO ( ) formatter . format ( tokens , realoutfile ) return realoutfile . getvalue ( ) else : formatter . format ( tokens , outfile ) except TypeError , err : if isinstance ( err . args [ 0 ] , str ) and 'unbound method format' in err . args [ 0 ] : raise TypeError ( 'format() argument must be a formatter instance, ' 'not a class' ) raise