nodes: 0, module; 1, function_definition; 2, function_name:ports_as_list; 3, parameters; 4, block; 5, identifier:port_str; 6, expression_statement; 7, if_statement; 8, if_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, if_statement; 16, expression_statement; 17, expression_statement; 18, expression_statement; 19, comment:# TCP ports listed first, then UDP ports; 20, if_statement; 21, if_statement; 22, if_statement; 23, return_statement; 24, comment:"""
      Parses a ports string into two list of individual tcp and udp ports.
  
      @input string containing a port list
      e.g. T:1,2,3,5-8 U:22,80,600-1024
  
      @return two list of sorted integers, for tcp and udp ports respectively.
      """; 25, not_operator; 26, block; 27, call; 28, block; 29, assignment; 30, assignment; 31, assignment; 32, assignment; 33, assignment; 34, comparison_operator:ports[b_tcp - 1] == ','; 35, block; 36, comparison_operator:ports[b_udp - 1] == ','; 37, block; 38, assignment; 39, assignment; 40, assignment; 41, boolean_operator; 42, block; 43, comment:# Only UDP ports; 44, elif_clause; 45, comment:# Only TCP ports; 46, elif_clause; 47, else_clause; 48, identifier:tports; 49, block; 50, identifier:uports; 51, block; 52, tuple; 53, identifier:port_str; 54, expression_statement; 55, return_statement; 56, identifier:ports_str_check_failed; 57, argument_list; 58, expression_statement; 59, return_statement; 60, identifier:tcp_list; 61, call; 62, identifier:udp_list; 63, call; 64, identifier:ports; 65, call; 66, identifier:b_tcp; 67, call; 68, identifier:b_udp; 69, call; 70, subscript; 71, string; 72, expression_statement; 73, subscript; 74, string; 75, expression_statement; 76, identifier:ports; 77, call; 78, identifier:tports; 79, string; 80, identifier:uports; 81, string; 82, comparison_operator:b_udp != -1; 83, comparison_operator:b_tcp != -1; 84, expression_statement; 85, expression_statement; 86, boolean_operator; 87, block; 88, boolean_operator; 89, block; 90, block; 91, for_statement; 92, expression_statement; 93, for_statement; 94, expression_statement; 95, identifier:tcp_list; 96, identifier:udp_list; 97, call; 98, list; 99, identifier:port_str; 100, call; 101, list; 102, identifier:list; 103, argument_list; 104, identifier:list; 105, argument_list; 106, attribute; 107, argument_list; 108, attribute; 109, argument_list; 110, attribute; 111, argument_list; 112, identifier:ports; 113, binary_operator:b_tcp - 1; 114, string_content:,; 115, assignment; 116, identifier:ports; 117, binary_operator:b_udp - 1; 118, string_content:,; 119, assignment; 120, identifier:port_str_arrange; 121, argument_list; 122, identifier:b_udp; 123, unary_operator; 124, identifier:b_tcp; 125, unary_operator; 126, assignment; 127, assignment; 128, comparison_operator:b_tcp == -1; 129, comparison_operator:b_udp != -1; 130, expression_statement; 131, comparison_operator:b_udp == -1; 132, comparison_operator:b_tcp != -1; 133, expression_statement; 134, expression_statement; 135, identifier:port; 136, call; 137, block; 138, call; 139, identifier:port; 140, call; 141, block; 142, call; 143, attribute; 144, argument_list; 145, None; 146, None; 147, attribute; 148, argument_list; 149, None; 150, None; 151, identifier:port_str; 152, identifier:replace; 153, string; 154, string; 155, identifier:ports; 156, identifier:find; 157, string:"T"; 158, identifier:ports; 159, identifier:find; 160, string:"U"; 161, identifier:b_tcp; 162, integer:1; 163, identifier:ports; 164, binary_operator:ports[:b_tcp - 1] + ports[b_tcp:]; 165, identifier:b_udp; 166, integer:1; 167, identifier:ports; 168, binary_operator:ports[:b_udp - 1] + ports[b_udp:]; 169, identifier:ports; 170, integer:1; 171, integer:1; 172, identifier:tports; 173, subscript; 174, identifier:uports; 175, subscript; 176, identifier:b_tcp; 177, unary_operator; 178, identifier:b_udp; 179, unary_operator; 180, assignment; 181, identifier:b_udp; 182, unary_operator; 183, identifier:b_tcp; 184, unary_operator; 185, assignment; 186, assignment; 187, attribute; 188, argument_list; 189, if_statement; 190, attribute; 191, argument_list; 192, attribute; 193, argument_list; 194, if_statement; 195, attribute; 196, argument_list; 197, identifier:LOGGER; 198, identifier:info; 199, string:"Invalid port value"; 200, identifier:LOGGER; 201, identifier:info; 202, string:"{0}: Port list malformed."; 203, string_content:; 204, subscript; 205, subscript; 206, subscript; 207, subscript; 208, identifier:ports; 209, slice; 210, identifier:ports; 211, slice; 212, integer:1; 213, integer:1; 214, identifier:uports; 215, subscript; 216, integer:1; 217, integer:1; 218, identifier:tports; 219, subscript; 220, identifier:tports; 221, identifier:ports; 222, identifier:tports; 223, identifier:split; 224, string; 225, comparison_operator:'-' in port; 226, block; 227, else_clause; 228, identifier:tcp_list; 229, identifier:sort; 230, identifier:uports; 231, identifier:split; 232, string; 233, comparison_operator:'-' in port; 234, block; 235, else_clause; 236, identifier:udp_list; 237, identifier:sort; 238, identifier:ports; 239, slice; 240, identifier:ports; 241, slice; 242, identifier:ports; 243, slice; 244, identifier:ports; 245, slice; 246, binary_operator:ports.index('T:') + 2; 247, call; 248, binary_operator:ports.index('U:') + 2; 249, identifier:ports; 250, slice; 251, identifier:ports; 252, slice; 253, string_content:,; 254, string; 255, identifier:port; 256, expression_statement; 257, block; 258, string_content:,; 259, string; 260, identifier:port; 261, expression_statement; 262, block; 263, binary_operator:b_tcp - 1; 264, identifier:b_tcp; 265, binary_operator:b_udp - 1; 266, identifier:b_udp; 267, call; 268, integer:2; 269, attribute; 270, argument_list; 271, call; 272, integer:2; 273, binary_operator:ports.index('U:') + 2; 274, binary_operator:ports.index('T:') + 2; 275, string_content:-; 276, call; 277, expression_statement; 278, string_content:-; 279, call; 280, expression_statement; 281, identifier:b_tcp; 282, integer:1; 283, identifier:b_udp; 284, integer:1; 285, attribute; 286, argument_list; 287, identifier:ports; 288, identifier:index; 289, string; 290, attribute; 291, argument_list; 292, call; 293, integer:2; 294, call; 295, integer:2; 296, attribute; 297, argument_list; 298, call; 299, attribute; 300, argument_list; 301, call; 302, identifier:ports; 303, identifier:index; 304, string; 305, string_content:U:; 306, identifier:ports; 307, identifier:index; 308, string; 309, attribute; 310, argument_list; 311, attribute; 312, argument_list; 313, identifier:tcp_list; 314, identifier:extend; 315, call; 316, attribute; 317, argument_list; 318, identifier:udp_list; 319, identifier:extend; 320, call; 321, attribute; 322, argument_list; 323, string_content:T:; 324, string_content:U:; 325, identifier:ports; 326, identifier:index; 327, string; 328, identifier:ports; 329, identifier:index; 330, string; 331, identifier:port_range_expand; 332, argument_list; 333, identifier:tcp_list; 334, identifier:append; 335, call; 336, identifier:port_range_expand; 337, argument_list; 338, identifier:udp_list; 339, identifier:append; 340, call; 341, string_content:U:; 342, string_content:T:; 343, identifier:port; 344, identifier:int; 345, argument_list; 346, identifier:port; 347, identifier:int; 348, argument_list; 349, identifier:port; 350, identifier:port
code: def ports_as_list(port_str):
      """
      Parses a ports string into two list of individual tcp and udp ports.
  
      @input string containing a port list
      e.g. T:1,2,3,5-8 U:22,80,600-1024
  
      @return two list of sorted integers, for tcp and udp ports respectively.
      """
      if not port_str:
          LOGGER.info("Invalid port value")
          return [None, None]
  
      if ports_str_check_failed(port_str):
          LOGGER.info("{0}: Port list malformed.")
          return [None, None]
  
      tcp_list = list()
      udp_list = list()
      ports = port_str.replace(' ', '')
      b_tcp = ports.find("T")
      b_udp = ports.find("U")
  
      if ports[b_tcp - 1] == ',':
          ports = ports[:b_tcp - 1] + ports[b_tcp:]
      if ports[b_udp - 1] == ',':
          ports = ports[:b_udp - 1] + ports[b_udp:]
      ports = port_str_arrange(ports)
  
      tports = ''
      uports = ''
      # TCP ports listed first, then UDP ports
      if b_udp != -1 and b_tcp != -1:
          tports = ports[ports.index('T:') + 2:ports.index('U:')]
          uports = ports[ports.index('U:') + 2:]
      # Only UDP ports
      elif b_tcp == -1 and b_udp != -1:
          uports = ports[ports.index('U:') + 2:]
      # Only TCP ports
      elif b_udp == -1 and b_tcp != -1:
          tports = ports[ports.index('T:') + 2:]
      else:
          tports = ports
  
      if tports:
          for port in tports.split(','):
              if '-' in port:
                  tcp_list.extend(port_range_expand(port))
              else:
                  tcp_list.append(int(port))
          tcp_list.sort()
      if uports:
          for port in uports.split(','):
              if '-' in port:
                  udp_list.extend(port_range_expand(port))
              else:
                  udp_list.append(int(port))
          udp_list.sort()
  
      return (tcp_list, udp_list)