def METHOD_NAME(self, attrs):
    """Validate if the mimetype is allowed or not."""
    # mimetype is provided, we directly check it
    if attrs["mimetype"] != "":
        attrs["extension"] = mimetypes.guess_extension(attrs["mimetype"])
    # mimetype is not provided, we have to guess it from the extension
    else:
        mimetypes.init()
        extension = splitext(attrs["filename"])[1]
        mimetype = mimetypes.types_map.get(extension)
        # extension is added to the data in order to be used later
        attrs["extension"] = extension
        attrs["mimetype"] = mimetype
    return attrs