nodes: 0, module; 1, function_definition; 2, function_name:rules; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, comment:# Sort the data in order to get a consistent output; 10, expression_statement; 11, return_statement; 12, comment:"""
          Returns a sorted list of firewall rules.
  
          Returns:
              list
          """; 13, assignment; 14, identifier:main_row; 15, attribute; 16, block; 17, assignment; 18, identifier:sorted_list; 19, identifier:list_of_rules; 20, list; 21, identifier:self; 22, identifier:dict_rules; 23, if_statement; 24, identifier:sorted_list; 25, call; 26, comparison_operator:'rules' in main_row; 27, block; 28, else_clause; 29, identifier:sorted; 30, argument_list; 31, string; 32, identifier:main_row; 33, for_statement; 34, block; 35, identifier:list_of_rules; 36, keyword_argument; 37, string_content:rules; 38, identifier:rule_row; 39, subscript; 40, block; 41, expression_statement; 42, expression_statement; 43, identifier:key; 44, lambda; 45, identifier:main_row; 46, string; 47, if_statement; 48, assignment; 49, call; 50, lambda_parameters; 51, tuple; 52, string_content:rules; 53, comparison_operator:'grants' in rule_row; 54, block; 55, else_clause; 56, identifier:fr; 57, call; 58, attribute; 59, argument_list; 60, identifier:fr; 61, call; 62, call; 63, call; 64, call; 65, call; 66, call; 67, call; 68, call; 69, call; 70, call; 71, string; 72, identifier:rule_row; 73, for_statement; 74, block; 75, identifier:FirewallRule; 76, argument_list; 77, identifier:list_of_rules; 78, identifier:append; 79, identifier:fr; 80, identifier:str; 81, argument_list; 82, identifier:str; 83, argument_list; 84, identifier:str; 85, argument_list; 86, identifier:str; 87, argument_list; 88, identifier:str; 89, argument_list; 90, identifier:str; 91, argument_list; 92, identifier:str; 93, argument_list; 94, identifier:str; 95, argument_list; 96, identifier:str; 97, argument_list; 98, identifier:str; 99, argument_list; 100, string_content:grants; 101, identifier:grant_row; 102, subscript; 103, block; 104, expression_statement; 105, expression_statement; 106, subscript; 107, subscript; 108, subscript; 109, attribute; 110, attribute; 111, attribute; 112, attribute; 113, attribute; 114, attribute; 115, attribute; 116, attribute; 117, attribute; 118, attribute; 119, identifier:rule_row; 120, string; 121, if_statement; 122, assignment; 123, call; 124, identifier:main_row; 125, string; 126, identifier:main_row; 127, string; 128, identifier:main_row; 129, string; 130, identifier:fr; 131, identifier:id; 132, identifier:fr; 133, identifier:name; 134, identifier:fr; 135, identifier:description; 136, identifier:fr; 137, identifier:rules_direction; 138, identifier:fr; 139, identifier:rules_ip_protocol; 140, identifier:fr; 141, identifier:rules_from_port; 142, identifier:fr; 143, identifier:rules_to_port; 144, identifier:fr; 145, identifier:rules_grants_group_id; 146, identifier:fr; 147, identifier:rules_grants_name; 148, identifier:fr; 149, identifier:rules_grants_cidr_ip; 150, string_content:grants; 151, comparison_operator:'group_id' in grant_row; 152, comment:# Set a var to not go over 80 chars; 153, block; 154, elif_clause; 155, else_clause; 156, identifier:fr; 157, call; 158, attribute; 159, argument_list; 160, string_content:id; 161, string_content:name; 162, string_content:description; 163, string; 164, identifier:grant_row; 165, expression_statement; 166, comment:# Some VPC grants don't specify a name; 167, if_statement; 168, expression_statement; 169, expression_statement; 170, comparison_operator:'cidr_ip' in grant_row; 171, block; 172, block; 173, identifier:FirewallRule; 174, argument_list; 175, identifier:list_of_rules; 176, identifier:append; 177, identifier:fr; 178, string_content:group_id; 179, assignment; 180, comparison_operator:'name' in grant_row; 181, block; 182, else_clause; 183, assignment; 184, call; 185, string; 186, identifier:grant_row; 187, expression_statement; 188, expression_statement; 189, raise_statement; 190, subscript; 191, subscript; 192, subscript; 193, keyword_argument; 194, keyword_argument; 195, keyword_argument; 196, keyword_argument; 197, identifier:group_id; 198, subscript; 199, string; 200, identifier:grant_row; 201, expression_statement; 202, block; 203, identifier:fr; 204, call; 205, attribute; 206, argument_list; 207, string_content:cidr_ip; 208, assignment; 209, call; 210, call; 211, identifier:main_row; 212, string; 213, identifier:main_row; 214, string; 215, identifier:main_row; 216, string; 217, identifier:rules_direction; 218, subscript; 219, identifier:rules_ip_protocol; 220, subscript; 221, identifier:rules_from_port; 222, subscript; 223, identifier:rules_to_port; 224, subscript; 225, identifier:grant_row; 226, string; 227, string_content:name; 228, assignment; 229, expression_statement; 230, identifier:FirewallRule; 231, argument_list; 232, identifier:list_of_rules; 233, identifier:append; 234, identifier:fr; 235, identifier:fr; 236, call; 237, attribute; 238, argument_list; 239, identifier:ValueError; 240, argument_list; 241, string_content:id; 242, string_content:name; 243, string_content:description; 244, identifier:rule_row; 245, string; 246, identifier:rule_row; 247, string; 248, identifier:rule_row; 249, string; 250, identifier:rule_row; 251, string; 252, string_content:group_id; 253, identifier:row_name; 254, subscript; 255, assignment; 256, subscript; 257, subscript; 258, subscript; 259, keyword_argument; 260, keyword_argument; 261, keyword_argument; 262, keyword_argument; 263, keyword_argument; 264, keyword_argument; 265, keyword_argument; 266, identifier:FirewallRule; 267, argument_list; 268, identifier:list_of_rules; 269, identifier:append; 270, identifier:fr; 271, string:"Unsupported grant:"; 272, identifier:grant_row; 273, string_content:direction; 274, string_content:ip_protocol; 275, string_content:from_port; 276, string_content:to_port; 277, identifier:grant_row; 278, string; 279, identifier:row_name; 280, None; 281, identifier:main_row; 282, string; 283, identifier:main_row; 284, string; 285, identifier:main_row; 286, string; 287, identifier:rules_direction; 288, subscript; 289, identifier:rules_ip_protocol; 290, subscript; 291, identifier:rules_from_port; 292, subscript; 293, identifier:rules_to_port; 294, subscript; 295, identifier:rules_grants_group_id; 296, identifier:group_id; 297, identifier:rules_grants_name; 298, identifier:row_name; 299, identifier:rules_description; 300, subscript; 301, subscript; 302, subscript; 303, subscript; 304, keyword_argument; 305, keyword_argument; 306, keyword_argument; 307, keyword_argument; 308, keyword_argument; 309, keyword_argument; 310, string_content:name; 311, string_content:id; 312, string_content:name; 313, string_content:description; 314, identifier:rule_row; 315, string; 316, identifier:rule_row; 317, string; 318, identifier:rule_row; 319, string; 320, identifier:rule_row; 321, string; 322, identifier:grant_row; 323, string; 324, identifier:main_row; 325, string; 326, identifier:main_row; 327, string; 328, identifier:main_row; 329, string; 330, identifier:rules_direction; 331, subscript; 332, identifier:rules_ip_protocol; 333, subscript; 334, identifier:rules_from_port; 335, subscript; 336, identifier:rules_to_port; 337, subscript; 338, identifier:rules_grants_cidr_ip; 339, subscript; 340, identifier:rules_description; 341, subscript; 342, string_content:direction; 343, string_content:ip_protocol; 344, string_content:from_port; 345, string_content:to_port; 346, string_content:description; 347, string_content:id; 348, string_content:name; 349, string_content:description; 350, identifier:rule_row; 351, string; 352, identifier:rule_row; 353, string; 354, identifier:rule_row; 355, string; 356, identifier:rule_row; 357, string; 358, identifier:grant_row; 359, string; 360, identifier:grant_row; 361, string; 362, string_content:direction; 363, string_content:ip_protocol; 364, string_content:from_port; 365, string_content:to_port; 366, string_content:cidr_ip; 367, string_content:description
code: def rules(self):
          """
          Returns a sorted list of firewall rules.
  
          Returns:
              list
          """
          list_of_rules = []
  
          for main_row in self.dict_rules:
              if 'rules' in main_row:
                  for rule_row in main_row['rules']:
                      if 'grants' in rule_row:
                          for grant_row in rule_row['grants']:
                              if 'group_id' in grant_row:
                                  # Set a var to not go over 80 chars
                                  group_id = grant_row['group_id']
  
                                  # Some VPC grants don't specify a name
                                  if 'name' in grant_row:
                                      row_name = grant_row['name']
                                  else:
                                      row_name = None
  
                                  fr = FirewallRule(
                                      main_row['id'],
                                      main_row['name'],
                                      main_row['description'],
                                      rules_direction=rule_row['direction'],
                                      rules_ip_protocol=rule_row['ip_protocol'],
                                      rules_from_port=rule_row['from_port'],
                                      rules_to_port=rule_row['to_port'],
                                      rules_grants_group_id=group_id,
                                      rules_grants_name=row_name,
                                      rules_description=grant_row['description'])
  
                                  list_of_rules.append(fr)
                              elif 'cidr_ip' in grant_row:
                                  fr = FirewallRule(
                                      main_row['id'],
                                      main_row['name'],
                                      main_row['description'],
                                      rules_direction=rule_row['direction'],
                                      rules_ip_protocol=rule_row['ip_protocol'],
                                      rules_from_port=rule_row['from_port'],
                                      rules_to_port=rule_row['to_port'],
                                      rules_grants_cidr_ip=grant_row['cidr_ip'],
                                      rules_description=grant_row['description'])
                                  list_of_rules.append(fr)
                              else:
                                  raise ValueError("Unsupported grant:",
                                                   grant_row)
                      else:
                          fr = FirewallRule(
                              main_row['id'],
                              main_row['name'],
                              main_row['description'],
                              rules_direction=rule_row['direction'],
                              rules_ip_protocol=rule_row['ip_protocol'],
                              rules_from_port=rule_row['from_port'],
                              rules_to_port=rule_row['to_port'])
                          list_of_rules.append(fr)
              else:
                  fr = FirewallRule(main_row['id'],
                                    main_row['name'],
                                    main_row['description'])
                  list_of_rules.append(fr)
  
          # Sort the data in order to get a consistent output
          sorted_list = sorted(list_of_rules,
                               key=lambda fr: (str(fr.id),
                                               str(fr.name),
                                               str(fr.description),
                                               str(fr.rules_direction),
                                               str(fr.rules_ip_protocol),
                                               str(fr.rules_from_port),
                                               str(fr.rules_to_port),
                                               str(fr.rules_grants_group_id),
                                               str(fr.rules_grants_name),
                                               str(fr.rules_grants_cidr_ip)))
  
          return sorted_list