nodes: 0, module; 1, function_definition; 2, function_name:sorted; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, expression_statement; 8, function_definition; 9, expression_statement; 10, comment:# make a copy!; 11, if_statement; 12, return_statement; 13, identifier:wantdirs; 14, False; 15, comment:"""
          Return sorted files in directory order
          """; 16, function_name:add_dir; 17, parameters; 18, block; 19, assignment; 20, identifier:wantdirs; 21, block; 22, list_comprehension; 23, identifier:dirs; 24, identifier:d; 25, expression_statement; 26, expression_statement; 27, if_statement; 28, identifier:result; 29, call; 30, expression_statement; 31, for_statement; 32, expression_statement; 33, call; 34, for_in_clause; 35, call; 36, call; 37, comparison_operator:d != self.base; 38, block; 39, identifier:set; 40, argument_list; 41, assignment; 42, identifier:f; 43, identifier:result; 44, block; 45, augmented_assignment; 46, attribute; 47, argument_list; 48, identifier:path_tuple; 49, call; 50, attribute; 51, argument_list; 52, attribute; 53, argument_list; 54, identifier:d; 55, attribute; 56, expression_statement; 57, assert_statement; 58, expression_statement; 59, attribute; 60, identifier:dirs; 61, call; 62, expression_statement; 63, identifier:result; 64, identifier:dirs; 65, attribute; 66, identifier:join; 67, list_splat; 68, identifier:sorted; 69, generator_expression; 70, identifier:dirs; 71, identifier:add; 72, identifier:d; 73, identifier:logger; 74, identifier:debug; 75, string; 76, identifier:d; 77, identifier:self; 78, identifier:base; 79, assignment; 80, comparison_operator:parent not in ('', '/'); 81, call; 82, identifier:self; 83, identifier:files; 84, identifier:set; 85, argument_list; 86, call; 87, identifier:os; 88, identifier:path; 89, identifier:path_tuple; 90, call; 91, for_in_clause; 92, string_content:add_dir added %s; 93, pattern_list; 94, call; 95, identifier:parent; 96, tuple; 97, identifier:add_dir; 98, argument_list; 99, identifier:add_dir; 100, argument_list; 101, attribute; 102, argument_list; 103, identifier:path; 104, identifier:result; 105, identifier:parent; 106, identifier:_; 107, attribute; 108, argument_list; 109, string; 110, string; 111, identifier:dirs; 112, identifier:parent; 113, identifier:dirs; 114, call; 115, attribute; 116, identifier:split; 117, identifier:path; 118, attribute; 119, identifier:split; 120, identifier:d; 121, string_content:/; 122, attribute; 123, argument_list; 124, identifier:os; 125, identifier:path; 126, identifier:os; 127, identifier:path; 128, attribute; 129, identifier:dirname; 130, identifier:f; 131, identifier:os; 132, identifier:path
code: def sorted(self, wantdirs=False):
          """
          Return sorted files in directory order
          """
  
          def add_dir(dirs, d):
              dirs.add(d)
              logger.debug('add_dir added %s', d)
              if d != self.base:
                  parent, _ = os.path.split(d)
                  assert parent not in ('', '/')
                  add_dir(dirs, parent)
  
          result = set(self.files)    # make a copy!
          if wantdirs:
              dirs = set()
              for f in result:
                  add_dir(dirs, os.path.dirname(f))
              result |= dirs
          return [os.path.join(*path_tuple) for path_tuple in
                  sorted(os.path.split(path) for path in result)]