code: def best_match(requested, allowed):
      
  
      requested = [parse_ctype(ctype) for ctype in quoted_split(requested, ',')]
  
      best_q = -1
      best_ctype = ''
      best_params = {}
      best_match = '*/*'
  
      # Walk the list of content types
      for ctype in allowed:
          # Compare to the accept list
          for ctype_mask, params in requested:
              try:
                  q = float(params.get('q', 1.0))
              except ValueError:
                  # Bad quality value
                  continue
  
              if q < best_q:
                  # Not any better
                  continue
              elif best_q == q:
                  # Base on the best match
                  if best_match.count('*') <= ctype_mask.count('*'):
                      continue
  
              # OK, see if we have a match
              if _match_mask(ctype_mask, ctype):
                  best_q = q
                  best_ctype = ctype
                  best_params = params
                  best_match = ctype_mask
  
      # Return the best match
      return best_ctype, best_params
docs: Determine the best content type to use for the request.
  
      :param ctypes: A list of the available content types.
  
      :returns: A tuple of the best match content type and the
                parameters for that content type.