def quality_mime_sort_key(qmt):
    """
    Media ranges can be overridden by more    specific media ranges or specific media    types. If more than one media range    applies to a given type, the most    specific reference has precedence.

    Example::

        1. text/plain;format=flowed
        2. text/plain
        3. text/*
        4. */*

    :param qmt:
    :return: Factor as tuple(quality,    type_factor, subtype_factor,    len_of_params)
    """
    value, params = qmt
    type_, subtype = value
    if type_ != '*':
        type_factor = 1
    else:
        type_factor = 0
    if subtype != '*':
        subtype_factor = 1
    else:
        subtype_factor = 0
    return params['q'] * -1, type_factor * -1, subtype_factor * -1, len(params
        ) * -1
