def _parser_dispatch(flavor):
valid_parsers = list(_valid_parsers.keys())<EOL>if flavor not in valid_parsers:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>.format(invalid=flavor, valid=valid_parsers))<EOL><DEDENT>if flavor in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if not _HAS_HTML5LIB:<EOL><INDENT>raise ImportError("<STR_LIT>")<EOL><DEDENT>if not _HAS_BS4:<EOL><INDENT>raise ImportError(<EOL>"<STR_LIT>")<EOL><DEDENT>import bs4<EOL>if LooseVersion(bs4.__version__) <= LooseVersion('<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not _HAS_LXML:<EOL><INDENT>raise ImportError("<STR_LIT>")<EOL><DEDENT><DEDENT>return _valid_parsers[flavor]<EOL>
Choose the parser based on the input flavor.

    Parameters
    ----------
    flavor : str
        The type of parser to use. This must be a valid backend.

    Returns
    -------
    cls : _HtmlFrameParser subclass
        The parser class based on the requested input flavor.

    Raises
    ------
    ValueError
        * If `flavor` is not a valid backend.
    ImportError
        * If you do not have the requested `flavor`