def parse_accept(header_value):
next_explicit_q = decimal.ExtendedContext.next_plus(decimal.Decimal('<STR_LIT>'))<EOL>headers = [parse_content_type(header)<EOL>for header in parse_list(header_value)]<EOL>for header in headers:<EOL><INDENT>q = header.parameters.pop('<STR_LIT:q>', None)<EOL>if q is None:<EOL><INDENT>q = '<STR_LIT:1.0>'<EOL><DEDENT>elif float(q) == <NUM_LIT:1.0>:<EOL><INDENT>q = float(next_explicit_q)<EOL>next_explicit_q = next_explicit_q.next_minus()<EOL><DEDENT>header.quality = float(q)<EOL><DEDENT>def ordering(left, right):<EOL><INDENT>"""<STR_LIT>"""<EOL>if left.quality != right.quality:<EOL><INDENT>return right.quality - left.quality<EOL><DEDENT>if left == right:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>if left > right:<EOL><INDENT>return -<NUM_LIT:1><EOL><DEDENT>return <NUM_LIT:1><EOL><DEDENT>return sorted(headers, key=functools.cmp_to_key(ordering))<EOL>
Parse an HTTP accept-like header.

    :param str header_value: the header value to parse
    :return: a :class:`list` of :class:`.ContentType` instances
        in decreasing quality order.  Each instance is augmented
        with the associated quality as a ``float`` property
        named ``quality``.

    ``Accept`` is a class of headers that contain a list of values
    and an associated preference value.  The ever present `Accept`_
    header is a perfect example.  It is a list of content types and
    an optional parameter named ``q`` that indicates the relative
    weight of a particular type.  The most basic example is::

        Accept: audio/*;q=0.2, audio/basic

    Which states that I prefer the ``audio/basic`` content type
    but will accept other ``audio`` sub-types with an 80% mark down.

    .. _Accept: http://tools.ietf.org/html/rfc7231#section-5.3.2