nodes: 0, module; 1, function_definition; 2, function_name:render_stats; 3, parameters; 4, block; 5, identifier:stats; 6, identifier:sort; 7, identifier:format; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, comment:"""
      Returns a StringIO containing the formatted statistics from _statsfile_.
  
      _sort_ is a list of fields to sort by.
      _format_ is the name of the method that pstats uses to format the data.
      """; 15, assignment; 16, call; 17, block; 18, call; 19, call; 20, attribute; 21, identifier:output; 22, call; 23, identifier:hasattr; 24, argument_list; 25, expression_statement; 26, attribute; 27, argument_list; 28, call; 29, argument_list; 30, identifier:output; 31, identifier:stream; 32, identifier:StdoutWrapper; 33, argument_list; 34, identifier:stats; 35, string:"stream"; 36, assignment; 37, identifier:stats; 38, identifier:sort_stats; 39, list_splat; 40, identifier:getattr; 41, argument_list; 42, attribute; 43, attribute; 44, identifier:sort; 45, identifier:stats; 46, identifier:format; 47, identifier:stats; 48, identifier:stream; 49, identifier:output; 50, identifier:stream
code: def render_stats(stats, sort, format):
      """
      Returns a StringIO containing the formatted statistics from _statsfile_.
  
      _sort_ is a list of fields to sort by.
      _format_ is the name of the method that pstats uses to format the data.
      """
      output = StdoutWrapper()
      if hasattr(stats, "stream"):
          stats.stream = output.stream
      stats.sort_stats(*sort)
      getattr(stats, format)()
      return output.stream