nodes: 0, module; 1, function_definition; 2, function_name:key; 3, parameters; 4, block; 5, identifier:self; 6, identifier:frame; 7, expression_statement; 8, function_definition; 9, comment:# Look up frame by exact match; 10, if_statement; 11, comment:# Look up parent frame for v2.2 frames; 12, if_statement; 13, comment:# Try each pattern; 14, for_statement; 15, return_statement; 16, string:"Return the sort key for the given frame."; 17, function_name:keytuple; 18, parameters; 19, block; 20, comparison_operator:type(frame) in self.frame_keys; 21, block; 22, boolean_operator; 23, block; 24, tuple_pattern; 25, attribute; 26, block; 27, call; 28, identifier:primary; 29, if_statement; 30, return_statement; 31, call; 32, attribute; 33, return_statement; 34, call; 35, comparison_operator:type(frame).__bases__[0] in self.frame_keys; 36, return_statement; 37, identifier:pattern; 38, identifier:key; 39, identifier:self; 40, identifier:re_keys; 41, if_statement; 42, identifier:keytuple; 43, argument_list; 44, comparison_operator:frame.frameno is None; 45, block; 46, tuple; 47, identifier:type; 48, argument_list; 49, identifier:self; 50, identifier:frame_keys; 51, call; 52, attribute; 53, argument_list; 54, subscript; 55, attribute; 56, call; 57, call; 58, block; 59, attribute; 60, attribute; 61, None; 62, return_statement; 63, identifier:primary; 64, integer:0; 65, attribute; 66, identifier:frame; 67, identifier:keytuple; 68, argument_list; 69, identifier:frame; 70, identifier:_in_version; 71, integer:2; 72, attribute; 73, integer:0; 74, identifier:self; 75, identifier:frame_keys; 76, identifier:keytuple; 77, argument_list; 78, attribute; 79, argument_list; 80, return_statement; 81, identifier:self; 82, identifier:unknown_key; 83, identifier:frame; 84, identifier:frameno; 85, tuple; 86, identifier:frame; 87, identifier:frameno; 88, subscript; 89, call; 90, identifier:__bases__; 91, subscript; 92, identifier:re; 93, identifier:match; 94, identifier:pattern; 95, attribute; 96, call; 97, identifier:primary; 98, integer:1; 99, attribute; 100, call; 101, identifier:type; 102, argument_list; 103, attribute; 104, subscript; 105, identifier:frame; 106, identifier:frameid; 107, identifier:keytuple; 108, argument_list; 109, identifier:self; 110, identifier:frame_keys; 111, identifier:type; 112, argument_list; 113, identifier:frame; 114, identifier:self; 115, identifier:frame_keys; 116, attribute; 117, integer:0; 118, identifier:key; 119, identifier:frame; 120, call; 121, identifier:__bases__; 122, identifier:type; 123, argument_list; 124, identifier:frame
code: def key(self, frame):
          "Return the sort key for the given frame."
          def keytuple(primary):
              if frame.frameno is None:
                  return (primary, 1)
              return (primary, 0, frame.frameno)
  
          # Look up frame by exact match
          if type(frame) in self.frame_keys:
              return keytuple(self.frame_keys[type(frame)])
  
          # Look up parent frame for v2.2 frames
          if frame._in_version(2) and type(frame).__bases__[0] in self.frame_keys:
              return keytuple(self.frame_keys[type(frame).__bases__[0]])
  
          # Try each pattern
          for (pattern, key) in self.re_keys:
              if re.match(pattern, frame.frameid):
                  return keytuple(key)
  
          return keytuple(self.unknown_key)