nodes: 0, module; 1, function_definition; 2, function_name:sort_versions; 3, parameters; 4, block; 5, default_parameter; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, function_definition; 12, expression_statement; 13, expression_statement; 14, for_statement; 15, comment:# replace letters found by a negative number; 16, expression_statement; 17, expression_statement; 18, if_statement; 19, comment:# Complete with zeros based on longest item and replace alphas with number; 20, expression_statement; 21, for_statement; 22, expression_statement; 23, return_statement; 24, identifier:versions; 25, tuple; 26, identifier:reverse; 27, False; 28, identifier:sep; 29, string; 30, comment:"""Sort a list of version number strings.
  
      This function ensures that the package sorting based on number name is
      performed correctly when including alpha, dev rc1 etc...
      """; 31, comparison_operator:versions == []; 32, block; 33, assignment; 34, function_name:toint; 35, parameters; 36, block; 37, assignment; 38, assignment; 39, identifier:item; 40, identifier:versions; 41, block; 42, assignment; 43, assignment; 44, call; 45, block; 46, assignment; 47, identifier:i; 48, call; 49, block; 50, assignment; 51, list_comprehension; 52, string_content:.; 53, identifier:versions; 54, list; 55, return_statement; 56, identifier:digits; 57, string; 58, identifier:x; 59, try_statement; 60, return_statement; 61, identifier:versions; 62, call; 63, pattern_list; 64, expression_list; 65, expression_statement; 66, expression_statement; 67, for_statement; 68, expression_statement; 69, expression_statement; 70, identifier:replace_dic; 71, dictionary; 72, identifier:alpha; 73, call; 74, identifier:len; 75, argument_list; 76, expression_statement; 77, identifier:nmax; 78, call; 79, identifier:range; 80, argument_list; 81, expression_statement; 82, for_statement; 83, expression_statement; 84, expression_statement; 85, expression_statement; 86, expression_statement; 87, identifier:new_versions; 88, call; 89, subscript; 90, for_in_clause; 91, list; 92, string_content:0123456789; 93, block; 94, except_clause; 95, identifier:n; 96, identifier:list; 97, argument_list; 98, identifier:new_versions; 99, identifier:alpha; 100, identifier:sizes; 101, list; 102, call; 103, call; 104, assignment; 105, assignment; 106, identifier:i; 107, identifier:it; 108, block; 109, call; 110, call; 111, identifier:sorted; 112, argument_list; 113, identifier:alpha; 114, assignment; 115, identifier:max; 116, argument_list; 117, call; 118, assignment; 119, identifier:z; 120, subscript; 121, block; 122, assignment; 123, augmented_assignment; 124, augmented_assignment; 125, assignment; 126, identifier:sorted; 127, argument_list; 128, identifier:n; 129, unary_operator; 130, identifier:n; 131, identifier:new_versions; 132, expression_statement; 133, block; 134, identifier:versions; 135, identifier:set; 136, argument_list; 137, identifier:set; 138, argument_list; 139, identifier:it; 140, call; 141, identifier:temp; 142, list; 143, expression_statement; 144, if_statement; 145, expression_statement; 146, attribute; 147, argument_list; 148, attribute; 149, argument_list; 150, identifier:alpha; 151, keyword_argument; 152, identifier:replace_dic; 153, call; 154, identifier:sizes; 155, identifier:len; 156, argument_list; 157, identifier:item; 158, list; 159, identifier:new_versions; 160, identifier:i; 161, if_statement; 162, identifier:nzeros; 163, binary_operator:nmax - len(item); 164, identifier:item; 165, binary_operator:[0]*nzeros; 166, identifier:item; 167, list; 168, subscript; 169, identifier:item; 170, identifier:new_versions; 171, keyword_argument; 172, integer:1; 173, assignment; 174, expression_statement; 175, attribute; 176, argument_list; 177, assignment; 178, not_operator; 179, block; 180, else_clause; 181, augmented_assignment; 182, identifier:sizes; 183, identifier:add; 184, call; 185, identifier:new_versions; 186, identifier:append; 187, identifier:temp; 188, identifier:reverse; 189, True; 190, identifier:dict; 191, argument_list; 192, identifier:new_versions; 193, comparison_operator:z in replace_dic; 194, block; 195, else_clause; 196, identifier:nmax; 197, call; 198, list; 199, identifier:nzeros; 200, subscript; 201, identifier:new_versions; 202, identifier:i; 203, identifier:reverse; 204, identifier:reverse; 205, identifier:n; 206, call; 207, assignment; 208, identifier:item; 209, identifier:split; 210, identifier:sep; 211, identifier:x; 212, call; 213, call; 214, expression_statement; 215, expression_statement; 216, expression_statement; 217, expression_statement; 218, expression_statement; 219, expression_statement; 220, while_statement; 221, for_statement; 222, block; 223, identifier:temp; 224, identifier:res; 225, identifier:len; 226, argument_list; 227, call; 228, identifier:z; 229, identifier:replace_dic; 230, expression_statement; 231, block; 232, identifier:len; 233, argument_list; 234, integer:0; 235, identifier:versions; 236, identifier:i; 237, identifier:int; 238, argument_list; 239, identifier:n; 240, identifier:x; 241, identifier:toint; 242, argument_list; 243, identifier:isinstance; 244, argument_list; 245, assignment; 246, assignment; 247, assignment; 248, assignment; 249, assignment; 250, assignment; 251, comparison_operator:u'' in res; 252, block; 253, identifier:r; 254, identifier:res; 255, block; 256, expression_statement; 257, identifier:temp; 258, identifier:zip; 259, argument_list; 260, call; 261, expression_statement; 262, identifier:item; 263, identifier:x; 264, identifier:i; 265, identifier:x; 266, identifier:int; 267, identifier:x; 268, call; 269, identifier:middle; 270, call; 271, identifier:tail; 272, call; 273, identifier:head; 274, call; 275, identifier:middle; 276, call; 277, identifier:res; 278, list; 279, string; 280, identifier:res; 281, expression_statement; 282, if_statement; 283, assignment; 284, identifier:alpha; 285, call; 286, attribute; 287, argument_list; 288, call; 289, identifier:u; 290, argument_list; 291, attribute; 292, argument_list; 293, identifier:toint; 294, argument_list; 295, identifier:toint; 296, argument_list; 297, identifier:toint; 298, argument_list; 299, identifier:head; 300, identifier:middle; 301, identifier:tail; 302, call; 303, call; 304, block; 305, identifier:res; 306, list; 307, identifier:list; 308, argument_list; 309, identifier:item; 310, identifier:append; 311, subscript; 312, attribute; 313, argument_list; 314, identifier:x; 315, call; 316, identifier:rstrip; 317, identifier:digits; 318, call; 319, call; 320, identifier:middle; 321, attribute; 322, argument_list; 323, identifier:is_unicode; 324, argument_list; 325, expression_statement; 326, identifier:x; 327, call; 328, identifier:replace_dic; 329, identifier:z; 330, identifier:item; 331, identifier:append; 332, identifier:z; 333, attribute; 334, argument_list; 335, attribute; 336, argument_list; 337, attribute; 338, argument_list; 339, identifier:res; 340, identifier:remove; 341, string; 342, identifier:r; 343, call; 344, identifier:range; 345, argument_list; 346, identifier:x; 347, identifier:lstrip; 348, identifier:digits; 349, call; 350, identifier:replace; 351, identifier:middle; 352, string; 353, call; 354, identifier:replace; 355, identifier:middle; 356, string; 357, attribute; 358, argument_list; 359, unary_operator; 360, unary_operator; 361, unary_operator; 362, attribute; 363, argument_list; 364, attribute; 365, argument_list; 366, identifier:alpha; 367, identifier:add; 368, identifier:r; 369, integer:1; 370, parenthesized_expression; 371, integer:1; 372, identifier:x; 373, identifier:lstrip; 374, identifier:digits; 375, identifier:x; 376, identifier:rstrip; 377, identifier:digits; 378, binary_operator:len(alpha)+1; 379, call; 380, integer:1; 381, identifier:len; 382, argument_list; 383, identifier:alpha
code: def sort_versions(versions=(), reverse=False, sep=u'.'):
      """Sort a list of version number strings.
  
      This function ensures that the package sorting based on number name is
      performed correctly when including alpha, dev rc1 etc...
      """
      if versions == []:
          return []
  
      digits = u'0123456789'
  
      def toint(x):
          try:
              n = int(x)
          except:
              n = x
          return n
      versions = list(versions)
      new_versions, alpha, sizes = [], set(), set()
  
      for item in versions:
          it = item.split(sep)
          temp = []
          for i in it:
              x = toint(i)
              if not isinstance(x, int):
                  x = u(x)
                  middle = x.lstrip(digits).rstrip(digits)
                  tail = toint(x.lstrip(digits).replace(middle, u''))
                  head = toint(x.rstrip(digits).replace(middle, u''))
                  middle = toint(middle)
                  res = [head, middle, tail]
                  while u'' in res:
                      res.remove(u'')
                  for r in res:
                      if is_unicode(r):
                          alpha.add(r)
              else:
                  res = [x]
              temp += res
          sizes.add(len(temp))
          new_versions.append(temp)
  
      # replace letters found by a negative number
      replace_dic = {}
      alpha = sorted(alpha, reverse=True)
      if len(alpha):
          replace_dic = dict(zip(alpha, list(range(-1, -(len(alpha)+1), -1))))
  
      # Complete with zeros based on longest item and replace alphas with number
      nmax = max(sizes)
      for i in range(len(new_versions)):
          item = []
          for z in new_versions[i]:
              if z in replace_dic:
                  item.append(replace_dic[z])
              else:
                  item.append(z)
  
          nzeros = nmax - len(item)
          item += [0]*nzeros
          item += [versions[i]]
          new_versions[i] = item
  
      new_versions = sorted(new_versions, reverse=reverse)
      return [n[-1] for n in new_versions]