def _compare_versions(v1, v2):
def normalize(v):<EOL><INDENT>v = re.sub(r'<STR_LIT>', '<STR_LIT>', v)<EOL>result = []<EOL>for part in v.split('<STR_LIT:.>'):<EOL><INDENT>m = re.match(r'<STR_LIT>', part)<EOL>if m:<EOL><INDENT>result.append(int(m.group(<NUM_LIT:1>)))<EOL>continue<EOL><DEDENT>m = re.match(r'<STR_LIT>', part)<EOL>if m:<EOL><INDENT>result.append(int(m.group(<NUM_LIT:1>)))<EOL>result.append(m.group(<NUM_LIT:2>))<EOL>continue<EOL><DEDENT>m = re.match(r'<STR_LIT>', part)<EOL>if m:<EOL><INDENT>result.append(int(m.group(<NUM_LIT:1>)))<EOL>result.append(m.group(<NUM_LIT:2>))<EOL>result.append(int(m.group(<NUM_LIT:3>)))<EOL>continue<EOL><DEDENT><DEDENT>return tuple(result)<EOL><DEDENT>n1 = normalize(v1)<EOL>n2 = normalize(v2)<EOL>return (n1 > n2) - (n1 < n2)<EOL>
Compare two version strings and return -1, 0 or 1 depending on the equality
of the subset of matching version numbers.

The implementation is inspired by the top answer at
http://stackoverflow.com/a/1714190/997768.