import mimetypes


def _guess_doc_mimetype(doc):
    """
    Guess the MIME type for a Weboob document.

    :param doc: A Weboob ``Document`` object.
    :return: The guessed MIME type or ``application/octet-stream``.
    """
    # Python mimetypes library expects a filename, so we have to build a
    # filename from the extension taken from Weboob data.
    guessed_mime = mimetypes.guess_type("foobar.%s" % doc.format)
    return guessed_mime[0] if guessed_mime[0] else 'application/octet-stream'