nodes: 0, module; 1, function_definition; 2, function_name:_prepare_sort_options; 3, parameters; 4, block; 5, identifier:self; 6, identifier:has_pk; 7, expression_statement; 8, expression_statement; 9, if_statement; 10, if_statement; 11, if_statement; 12, return_statement; 13, comment:"""
          Prepare "sort" options to use when calling the collection, depending
          on "_sort" and "_sort_limits" attributes
          """; 14, assignment; 15, boolean_operator; 16, block; 17, comparison_operator:self._sort_limits is not None; 18, block; 19, boolean_operator; 20, block; 21, identifier:sort_options; 22, identifier:sort_options; 23, dictionary; 24, comparison_operator:self._sort is not None; 25, not_operator; 26, expression_statement; 27, attribute; 28, None; 29, if_statement; 30, expression_statement; 31, not_operator; 32, comparison_operator:self._sort is None; 33, expression_statement; 34, attribute; 35, None; 36, identifier:has_pk; 37, call; 38, identifier:self; 39, identifier:_sort_limits; 40, boolean_operator; 41, block; 42, elif_clause; 43, call; 44, identifier:sort_options; 45, attribute; 46, None; 47, assignment; 48, identifier:self; 49, identifier:_sort; 50, attribute; 51, argument_list; 52, comparison_operator:'start' in self._sort_limits; 53, comparison_operator:'num' not in self._sort_limits; 54, expression_statement; 55, boolean_operator; 56, block; 57, attribute; 58, argument_list; 59, identifier:self; 60, identifier:_sort; 61, identifier:sort_options; 62, None; 63, identifier:sort_options; 64, identifier:update; 65, attribute; 66, string; 67, attribute; 68, string; 69, attribute; 70, assignment; 71, comparison_operator:'num' in self._sort_limits; 72, comparison_operator:'start' not in self._sort_limits; 73, expression_statement; 74, identifier:sort_options; 75, identifier:update; 76, attribute; 77, identifier:self; 78, identifier:_sort; 79, string_content:start; 80, identifier:self; 81, identifier:_sort_limits; 82, string_content:num; 83, identifier:self; 84, identifier:_sort_limits; 85, subscript; 86, unary_operator; 87, string; 88, attribute; 89, string; 90, attribute; 91, assignment; 92, identifier:self; 93, identifier:_sort_limits; 94, attribute; 95, string; 96, integer:1; 97, string_content:num; 98, identifier:self; 99, identifier:_sort_limits; 100, string_content:start; 101, identifier:self; 102, identifier:_sort_limits; 103, subscript; 104, integer:0; 105, identifier:self; 106, identifier:_sort_limits; 107, string_content:num; 108, attribute; 109, string; 110, identifier:self; 111, identifier:_sort_limits; 112, string_content:start
code: def _prepare_sort_options(self, has_pk):
          """
          Prepare "sort" options to use when calling the collection, depending
          on "_sort" and "_sort_limits" attributes
          """
          sort_options = {}
          if self._sort is not None and not has_pk:
              sort_options.update(self._sort)
          if self._sort_limits is not None:
              if 'start' in self._sort_limits and 'num' not in self._sort_limits:
                  self._sort_limits['num'] = -1
              elif 'num' in self._sort_limits and 'start' not in self._sort_limits:
                  self._sort_limits['start'] = 0
              sort_options.update(self._sort_limits)
          if not sort_options and self._sort is None:
              sort_options = None
          return sort_options