def _best_version(fields):
def _has_marker(keys, markers):<EOL><INDENT>for marker in markers:<EOL><INDENT>if marker in keys:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL><DEDENT>keys = []<EOL>for key, value in fields.items():<EOL><INDENT>if value in ([], '<STR_LIT>', None):<EOL><INDENT>continue<EOL><DEDENT>keys.append(key)<EOL><DEDENT>possible_versions = ['<STR_LIT:1.0>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']<EOL>for key in keys:<EOL><INDENT>if key not in _241_FIELDS and '<STR_LIT:1.0>' in possible_versions:<EOL><INDENT>possible_versions.remove('<STR_LIT:1.0>')<EOL><DEDENT>if key not in _314_FIELDS and '<STR_LIT>' in possible_versions:<EOL><INDENT>possible_versions.remove('<STR_LIT>')<EOL><DEDENT>if key not in _345_FIELDS and '<STR_LIT>' in possible_versions:<EOL><INDENT>possible_versions.remove('<STR_LIT>')<EOL><DEDENT>if key not in _426_FIELDS and '<STR_LIT>' in possible_versions:<EOL><INDENT>possible_versions.remove('<STR_LIT>')<EOL><DEDENT><DEDENT>if len(possible_versions) == <NUM_LIT:1>:<EOL><INDENT>return possible_versions[<NUM_LIT:0>]   <EOL><DEDENT>elif len(possible_versions) == <NUM_LIT:0>:<EOL><INDENT>raise MetadataConflictError('<STR_LIT>')<EOL><DEDENT>is_1_1 = '<STR_LIT>' in possible_versions and _has_marker(keys, _314_MARKERS)<EOL>is_1_2 = '<STR_LIT>' in possible_versions and _has_marker(keys, _345_MARKERS)<EOL>is_2_0 = '<STR_LIT>' in possible_versions and _has_marker(keys, _426_MARKERS)<EOL>if int(is_1_1) + int(is_1_2) + int(is_2_0) > <NUM_LIT:1>:<EOL><INDENT>raise MetadataConflictError('<STR_LIT>')<EOL><DEDENT>if not is_1_1 and not is_1_2 and not is_2_0:<EOL><INDENT>if PKG_INFO_PREFERRED_VERSION in possible_versions:<EOL><INDENT>return PKG_INFO_PREFERRED_VERSION<EOL><DEDENT><DEDENT>if is_1_1:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>if is_1_2:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return '<STR_LIT>'<EOL>
Detect the best version depending on the fields used.