# Path: mom/_compat.py
#   INT_MAX = sys.maxsize
#   INT_MAX = sys.maxint
# INT64_MAX = (1 << 63) - 1
# INT32_MAX = (1 << 31) - 1
# INT16_MAX = (1 << 15) - 1
# UINT128_MAX = (1 << 128) - 1    # 340282366920938463463374607431768211455L
# UINT64_MAX = 0xffffffffffffffff  # ((1 << 64) - 1)
# UINT32_MAX = 0xffffffff  # ((1 << 32) - 1)
# UINT16_MAX = 0xffff  # ((1 << 16) - 1)
# UINT8_MAX = 0xff
#   MACHINE_WORD_SIZE = 64
#   UINT_MAX = UINT64_MAX
#   MACHINE_WORD_SIZE = 32
#   UINT_MAX = UINT32_MAX
#   MACHINE_WORD_SIZE = 64
#   UINT_MAX = UINT64_MAX
#   LONG_TYPE = long
#   LONG_TYPE = int
#   INT_TYPE = long
#   INTEGER_TYPES = (int, long)
#   INT_TYPE = int
#   INTEGER_TYPES = (int,)
#   BYTES_TYPE = bytes
#   BYTES_TYPE = str
#   UNICODE_TYPE = unicode
#   BASESTRING_TYPE = basestring
#   HAVE_PYTHON3 = False
#   UNICODE_TYPE = str
#   BASESTRING_TYPE = (str, bytes)
#   HAVE_PYTHON3 = True
# ZERO_BYTE = byte_literal("\x00")
# EMPTY_BYTE = byte_literal("")
# EQUAL_BYTE = byte_literal("=")
# PLUS_BYTE = byte_literal("+")
# HYPHEN_BYTE = byte_literal("-")
# FORWARD_SLASH_BYTE = byte_literal("/")
# UNDERSCORE_BYTE = byte_literal("_")
# DIGIT_ZERO_BYTE = byte_literal("0")
# HAVE_LITTLE_ENDIAN = bool(struct.pack("h", 1) == "\x01\x00")
#   def byte_ord(byte_):
#   def byte_ord(byte_):
#   def byte_literal(literal):
#   def byte_literal(literal):
#   def dict_each(func, iterable):
#   def dict_each(func, iterable):
#   def next(iterator, default=throw):
#   def generate_random_bytes(count):
#     def generate_random_bytes(count):
#       def generate_random_bytes(count):
#       def generate_random_bytes(_):
# def get_word_alignment(num, force_arch=64,
#                        _machine_word_size=MACHINE_WORD_SIZE):
#   class Throw(object):
# 
# Path: mom/builtins.py
# def byte(number):
# def bytes_leading(raw_bytes, needle=_compat.ZERO_BYTE):
# def bytes_trailing(raw_bytes, needle=_compat.ZERO_BYTE):
# def bin(number, prefix="0b"):
# def hex(number, prefix="0x"):
# def is_sequence(obj):
# def is_unicode(obj):
# def is_bytes(obj):
# def is_bytes_or_unicode(obj):
# def is_integer(obj):
# def integer_byte_length(number):
# def integer_byte_size(number):
# def integer_bit_length(number):
# def integer_bit_size(number):
# def integer_bit_count(number):
# def is_even(num):
# def is_odd(num):
# def is_positive(num):
# def is_negative(num):


from mom import _compat
from mom import builtins
      float(params["q"]) < 0):
    params["q"] = "1"

  return type, subtype, params


def fitness_and_quality_parsed(mime_type, parsed_ranges):
  """Find the best match for a mime-type amongst parsed media-ranges.

  :param mime_type:
      The mime-type to compare.
  :param parsed_ranges:
      A list of media ranges that have already been parsed by
      parsed_media_range().
  :return:
      A tuple of the fitness value and the value of the 'q'
      quality parameter of the best match, or (-1, 0) if no match was
      found.
  """
  best_fitness = -1
  best_fit_q = 0
  (target_type, target_subtype, target_params) = parse_media_range(mime_type)
  for (main_type, subtype, params) in parsed_ranges:
    type_match = (main_type == target_type or
                  main_type == ASTERISK_BYTE or
                  target_type == ASTERISK_BYTE)
    subtype_match = (subtype == target_subtype or
                     subtype == ASTERISK_BYTE or
                     target_subtype == ASTERISK_BYTE)
    if type_match and subtype_match:

# Path: mom/_compat.py
#   INT_MAX = sys.maxsize
#   INT_MAX = sys.maxint
# INT64_MAX = (1 << 63) - 1
# INT32_MAX = (1 << 31) - 1
# INT16_MAX = (1 << 15) - 1
# UINT128_MAX = (1 << 128) - 1    # 340282366920938463463374607431768211455L
# UINT64_MAX = 0xffffffffffffffff  # ((1 << 64) - 1)
# UINT32_MAX = 0xffffffff  # ((1 << 32) - 1)
# UINT16_MAX = 0xffff  # ((1 << 16) - 1)
# UINT8_MAX = 0xff
#   MACHINE_WORD_SIZE = 64
#   UINT_MAX = UINT64_MAX
#   MACHINE_WORD_SIZE = 32
#   UINT_MAX = UINT32_MAX
#   MACHINE_WORD_SIZE = 64
#   UINT_MAX = UINT64_MAX
#   LONG_TYPE = long
#   LONG_TYPE = int
#   INT_TYPE = long
#   INTEGER_TYPES = (int, long)
#   INT_TYPE = int
#   INTEGER_TYPES = (int,)
#   BYTES_TYPE = bytes
#   BYTES_TYPE = str
#   UNICODE_TYPE = unicode
#   BASESTRING_TYPE = basestring
#   HAVE_PYTHON3 = False
#   UNICODE_TYPE = str
#   BASESTRING_TYPE = (str, bytes)
#   HAVE_PYTHON3 = True
# ZERO_BYTE = byte_literal("\x00")
# EMPTY_BYTE = byte_literal("")
# EQUAL_BYTE = byte_literal("=")
# PLUS_BYTE = byte_literal("+")
# HYPHEN_BYTE = byte_literal("-")
# FORWARD_SLASH_BYTE = byte_literal("/")
# UNDERSCORE_BYTE = byte_literal("_")
# DIGIT_ZERO_BYTE = byte_literal("0")
# HAVE_LITTLE_ENDIAN = bool(struct.pack("h", 1) == "\x01\x00")
#   def byte_ord(byte_):
#   def byte_ord(byte_):
#   def byte_literal(literal):
#   def byte_literal(literal):
#   def dict_each(func, iterable):
#   def dict_each(func, iterable):
#   def next(iterator, default=throw):
#   def generate_random_bytes(count):
#     def generate_random_bytes(count):
#       def generate_random_bytes(count):
#       def generate_random_bytes(_):
# def get_word_alignment(num, force_arch=64,
#                        _machine_word_size=MACHINE_WORD_SIZE):
#   class Throw(object):
# 
# Path: mom/builtins.py
# def byte(number):
# def bytes_leading(raw_bytes, needle=_compat.ZERO_BYTE):
# def bytes_trailing(raw_bytes, needle=_compat.ZERO_BYTE):
# def bin(number, prefix="0b"):
# def hex(number, prefix="0x"):
# def is_sequence(obj):
# def is_unicode(obj):
# def is_bytes(obj):
# def is_bytes_or_unicode(obj):
# def is_integer(obj):
# def integer_byte_length(number):
# def integer_byte_size(number):
# def integer_bit_length(number):
# def integer_bit_size(number):
# def integer_bit_count(number):
# def is_even(num):
# def is_odd(num):
# def is_positive(num):
# def is_negative(num):


# Path: mom/mimeparse.py
from mom import _compat
from mom import builtins

      float(params["q"]) < 0):
    params["q"] = "1"

  return type, subtype, params


def fitness_and_quality_parsed(mime_type, parsed_ranges):
  """Find the best match for a mime-type amongst parsed media-ranges.

  :param mime_type:
      The mime-type to compare.
  :param parsed_ranges:
      A list of media ranges that have already been parsed by
      parsed_media_range().
  :return:
      A tuple of the fitness value and the value of the 'q'
      quality parameter of the best match, or (-1, 0) if no match was
      found.
  """
  best_fitness = -1
  best_fit_q = 0
  (target_type, target_subtype, target_params) = parse_media_range(mime_type)
  for (main_type, subtype, params) in parsed_ranges:
    type_match = (main_type == target_type or
                  main_type == ASTERISK_BYTE or
                  target_type == ASTERISK_BYTE)
    subtype_match = (subtype == target_subtype or
                     subtype == ASTERISK_BYTE or
                     target_subtype == ASTERISK_BYTE)
    if type_match and subtype_match:

      param_matches = builtins.reduce(lambda x, y: x + y, [