nodes: 0, module; 1, function_definition; 2, function_name:_get_sorted_iterator; 3, parameters; 4, block; 5, identifier:self; 6, identifier:iterator; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, import_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, comment:"""
          Get the iterator over the sorted items.
  
          This function decides whether the items can be sorted in memory or on disk.
          :return:
          """; 15, assignment; 16, comparison_operator:len(lines) < self.max_lines; 17, block; 18, dotted_name; 19, assignment; 20, assignment; 21, call; 22, identifier:lines; 23, call; 24, call; 25, attribute; 26, return_statement; 27, identifier:tempfile; 28, identifier:tmp_dir; 29, call; 30, identifier:fnames; 31, call; 32, identifier:SortedIteratorMerger; 33, argument_list; 34, identifier:list; 35, argument_list; 36, identifier:len; 37, argument_list; 38, identifier:self; 39, identifier:max_lines; 40, call; 41, attribute; 42, argument_list; 43, attribute; 44, argument_list; 45, list_comprehension; 46, attribute; 47, call; 48, identifier:lines; 49, identifier:iter; 50, argument_list; 51, identifier:tempfile; 52, identifier:mkdtemp; 53, identifier:self; 54, identifier:_split; 55, call; 56, identifier:tmp_dir; 57, call; 58, for_in_clause; 59, identifier:self; 60, identifier:key; 61, identifier:next; 62, argument_list; 63, call; 64, identifier:chain; 65, argument_list; 66, identifier:unpickle_iter; 67, argument_list; 68, identifier:fname; 69, identifier:fnames; 70, identifier:iterator; 71, identifier:sorted; 72, argument_list; 73, list; 74, identifier:iterator; 75, call; 76, identifier:lines; 77, keyword_argument; 78, identifier:lines; 79, identifier:open; 80, argument_list; 81, identifier:key; 82, attribute; 83, identifier:fname; 84, string; 85, identifier:self; 86, identifier:key; 87, string_content:rb
code: def _get_sorted_iterator(self, iterator):
          """
          Get the iterator over the sorted items.
  
          This function decides whether the items can be sorted in memory or on disk.
          :return:
          """
          lines = list(next(iterator))
          if len(lines) < self.max_lines:
              return iter(sorted(lines, key=self.key))
  
          import tempfile
          tmp_dir = tempfile.mkdtemp()
          fnames = self._split(chain([lines], iterator), tmp_dir)
          return SortedIteratorMerger([unpickle_iter(open(fname, 'rb')) for fname in fnames], self.key)