def _c3_merge(sequences, cls, context):
result = []<EOL>while True:<EOL><INDENT>sequences = [s for s in sequences if s]  <EOL>if not sequences:<EOL><INDENT>return result<EOL><DEDENT>for s1 in sequences:  <EOL><INDENT>candidate = s1[<NUM_LIT:0>]<EOL>for s2 in sequences:<EOL><INDENT>if candidate in s2[<NUM_LIT:1>:]:<EOL><INDENT>candidate = None<EOL>break  <EOL><DEDENT><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if not candidate:<EOL><INDENT>raise exceptions.InconsistentMroError(<EOL>message="<STR_LIT>"<EOL>"<STR_LIT>",<EOL>mros=sequences,<EOL>cls=cls,<EOL>context=context,<EOL>)<EOL><DEDENT>result.append(candidate)<EOL>for seq in sequences:<EOL><INDENT>if seq[<NUM_LIT:0>] == candidate:<EOL><INDENT>del seq[<NUM_LIT:0>]<EOL><DEDENT><DEDENT><DEDENT>return None<EOL>
Merges MROs in *sequences* to a single MRO using the C3 algorithm.

    Adapted from http://www.python.org/download/releases/2.3/mro/.