nodes: 0, module; 1, function_definition; 2, function_name:_resolve_sort_by; 3, parameters; 4, block; 5, identifier:sort_by; 6, identifier:flag_radius_query; 7, expression_statement; 8, if_statement; 9, return_statement; 10, comment:"""
          Result ``sort_by`` argument.
  
          :param sort_by: str, or sqlalchemy ORM attribute.
          :param flag_radius_query:
          :return:
          """; 11, comparison_operator:sort_by is None; 12, block; 13, elif_clause; 14, else_clause; 15, identifier:sort_by; 16, identifier:sort_by; 17, None; 18, if_statement; 19, call; 20, block; 21, block; 22, identifier:flag_radius_query; 23, block; 24, identifier:isinstance; 25, argument_list; 26, if_statement; 27, expression_statement; 28, expression_statement; 29, identifier:sort_by; 30, identifier:string_types; 31, comparison_operator:sort_by.lower() == SORT_BY_DIST; 32, block; 33, elif_clause; 34, assignment; 35, assignment; 36, call; 37, identifier:SORT_BY_DIST; 38, if_statement; 39, expression_statement; 40, comparison_operator:sort_by not in SimpleZipcode.__table__.columns; 41, block; 42, identifier:sort_by; 43, attribute; 44, identifier:sort_by; 45, identifier:SORT_BY_DIST; 46, attribute; 47, argument_list; 48, comparison_operator:flag_radius_query is False; 49, block; 50, assignment; 51, identifier:sort_by; 52, attribute; 53, expression_statement; 54, raise_statement; 55, identifier:sort_by; 56, identifier:name; 57, identifier:sort_by; 58, identifier:lower; 59, identifier:flag_radius_query; 60, False; 61, expression_statement; 62, raise_statement; 63, identifier:sort_by; 64, identifier:SORT_BY_DIST; 65, attribute; 66, identifier:columns; 67, assignment; 68, call; 69, assignment; 70, call; 71, identifier:SimpleZipcode; 72, identifier:__table__; 73, identifier:msg; 74, string:"`sort_by` arg has to be one of the Zipcode attribute or 'dist'!"; 75, identifier:ValueError; 76, argument_list; 77, identifier:msg; 78, string:"`sort_by` arg can be 'dist' only under distance based query!"; 79, identifier:ValueError; 80, argument_list; 81, identifier:msg; 82, identifier:msg
code: def _resolve_sort_by(sort_by, flag_radius_query):
          """
          Result ``sort_by`` argument.
  
          :param sort_by: str, or sqlalchemy ORM attribute.
          :param flag_radius_query:
          :return:
          """
          if sort_by is None:
              if flag_radius_query:
                  sort_by = SORT_BY_DIST
          elif isinstance(sort_by, string_types):
              if sort_by.lower() == SORT_BY_DIST:
                  if flag_radius_query is False:
                      msg = "`sort_by` arg can be 'dist' only under distance based query!"
                      raise ValueError(msg)
                  sort_by = SORT_BY_DIST
              elif sort_by not in SimpleZipcode.__table__.columns:
                  msg = "`sort_by` arg has to be one of the Zipcode attribute or 'dist'!"
                  raise ValueError(msg)
          else:
              sort_by = sort_by.name
  
          return sort_by