def _get_format(format, fname, inp=None):
fmt = None<EOL>err = True<EOL>if format is not None:<EOL><INDENT>if format in fmt_to_exts:<EOL><INDENT>fmt = format<EOL>err = False<EOL><DEDENT><DEDENT>elif fname:<EOL><INDENT>file_ext = os.path.splitext(fname)[<NUM_LIT:1>][len(os.path.extsep):]<EOL>for fmt_name, exts in fmt_to_exts.items():<EOL><INDENT>if file_ext in exts:<EOL><INDENT>fmt = fmt_name<EOL>err = False<EOL><DEDENT><DEDENT><DEDENT>if fmt is None:<EOL><INDENT>if inp is not None:<EOL><INDENT>fmt = _guess_fmt_from_bytes(inp)<EOL>err = False<EOL><DEDENT><DEDENT>if err:<EOL><INDENT>err_string = '<STR_LIT>'<EOL>what = []<EOL>for k, v in {format: '<STR_LIT>',<EOL>fname: '<STR_LIT:filename>', inp: '<STR_LIT>'}.items():<EOL><INDENT>if k:<EOL><INDENT>what.append(v)<EOL><DEDENT><DEDENT>if not what:<EOL><INDENT>what.append('<STR_LIT>')<EOL><DEDENT>err_string += '<STR_LIT:U+002CU+0020>'.join(what)<EOL>raise AnyMarkupError(err_string)<EOL><DEDENT>return fmt<EOL>
Try to guess markup format of given input.

    Args:
        format: explicit format override to use
        fname: name of file, if a file was used to read `inp`
        inp: optional bytestring to guess format of (can be None, if markup
            format is to be guessed only from `format` and `fname`)
    Returns:
        guessed format (a key of fmt_to_exts dict)
    Raises:
        AnyMarkupError if explicit format override has unsupported value
            or if it's impossible to guess the format