def best_match_accept_mimetype(request, representations, default=None):
    if ((representations is None) or (len(representations) < 1)):
        return default
    try:
        accept_mimetypes = get_accept_mimetypes(request)
        if ((accept_mimetypes is None) or (len(accept_mimetypes) < 1)):
            return default
        for (accept_type, qual) in accept_mimetypes:
            if (accept_type in representations):
                return accept_type
        for (accept_type, qual) in accept_mimetypes:
            type_part = str(accept_type).split(';', 1)[0]
            if (type_part in representations):
                return type_part
        for (accept_type, qual) in accept_mimetypes:
            if ((accept_type == '*') or (accept_type == '*/*') or (accept_type == '*.*')):
                return default
    except (AttributeError, KeyError):
        return default
def best_match_accept_mimetype(request, representations, default=None):
    if ((representations is None) or (len(representations) < 1)):
        return default
    try:
        accept_mimetypes = get_accept_mimetypes(request)
        if ((accept_mimetypes is None) or (len(accept_mimetypes) < 1)):
            return default
        for (accept_type, qual) in accept_mimetypes:
            if (accept_type in representations):
                return accept_type
        for (accept_type, qual) in accept_mimetypes:
            type_part = str(accept_type).split(';', 1)[0]
            if (type_part in representations):
                return type_part
        for (accept_type, qual) in accept_mimetypes:
            if ((accept_type == '*') or (accept_type == '*/*') or (accept_type == '*.*')):
                return default
    except (AttributeError, KeyError):
        return default