def get_accepted_mimetype(accept_header, choices=None):
    """Return the preferred mimetype from an Accept header

    If `choices` is given, return the first match,
    otherwise return the first accepted item

    Return `None` if choices is given and no match is found,
    or nothing is specified.
    """
    for mime, q in _parse_accept_header(accept_header):
        if choices:
            if mime in choices:
                return mime
            else:
                continue
        else:
            return mime
    return None
Return the preferred mimetype from an Accept header

If `choices` is given, return the first match,
otherwise return the first accepted item

Return `None` if choices is given and no match is found,
or nothing is specified.
jupyterhub/utils.py