nodes: 0, module; 1, function_definition; 2, function_name:eval_field; 3, parameters; 4, block; 5, identifier:field; 6, identifier:asc; 7, expression_statement; 8, if_statement; 9, comment:"""Evaluate a field for sorting purpose.
  
      :param field: Field definition (string, dict or callable).
      :param asc: ``True`` if order is ascending, ``False`` if descending.
      :returns: Dictionary with the sort field query.
      """; 10, call; 11, block; 12, elif_clause; 13, else_clause; 14, identifier:isinstance; 15, argument_list; 16, if_statement; 17, call; 18, block; 19, block; 20, identifier:field; 21, identifier:dict; 22, identifier:asc; 23, block; 24, else_clause; 25, identifier:callable; 26, argument_list; 27, return_statement; 28, expression_statement; 29, if_statement; 30, return_statement; 31, return_statement; 32, comment:# Field should only have one key and must have an order subkey.; 33, block; 34, identifier:field; 35, call; 36, assignment; 37, not_operator; 38, block; 39, dictionary; 40, identifier:field; 41, expression_statement; 42, expression_statement; 43, expression_statement; 44, return_statement; 45, identifier:field; 46, argument_list; 47, pattern_list; 48, call; 49, identifier:asc; 50, expression_statement; 51, pair; 52, assignment; 53, assignment; 54, assignment; 55, identifier:field; 56, identifier:asc; 57, identifier:key; 58, identifier:key_asc; 59, identifier:parse_sort_field; 60, argument_list; 61, assignment; 62, identifier:key; 63, dictionary; 64, identifier:field; 65, call; 66, identifier:key; 67, subscript; 68, subscript; 69, call; 70, identifier:field; 71, identifier:key_asc; 72, not_operator; 73, pair; 74, attribute; 75, argument_list; 76, call; 77, integer:0; 78, subscript; 79, string; 80, identifier:reverse_order; 81, argument_list; 82, identifier:key_asc; 83, string; 84, conditional_expression:'asc' if key_asc else 'desc'; 85, identifier:copy; 86, identifier:deepcopy; 87, identifier:field; 88, identifier:list; 89, argument_list; 90, identifier:field; 91, identifier:key; 92, string_content:order; 93, subscript; 94, string_content:order; 95, string; 96, identifier:key_asc; 97, string; 98, call; 99, subscript; 100, string; 101, string_content:asc; 102, string_content:desc; 103, attribute; 104, argument_list; 105, identifier:field; 106, identifier:key; 107, string_content:order; 108, identifier:field; 109, identifier:keys
code: def eval_field(field, asc):
      """Evaluate a field for sorting purpose.
  
      :param field: Field definition (string, dict or callable).
      :param asc: ``True`` if order is ascending, ``False`` if descending.
      :returns: Dictionary with the sort field query.
      """
      if isinstance(field, dict):
          if asc:
              return field
          else:
              # Field should only have one key and must have an order subkey.
              field = copy.deepcopy(field)
              key = list(field.keys())[0]
              field[key]['order'] = reverse_order(field[key]['order'])
              return field
      elif callable(field):
          return field(asc)
      else:
          key, key_asc = parse_sort_field(field)
          if not asc:
              key_asc = not key_asc
          return {key: {'order': 'asc' if key_asc else 'desc'}}