def METHOD_NAME(cls, tag, filename):
    # file objects may have a .name parameter
    name = getattr(filename, 'name', None)
    name = name or filename
    try:
        mtype, _ = mimetypes.guess_type(name)
        if not mtype.startswith('{}/'.format(tag)):
            return None
        return mtype[len('{}/'.format(tag)):]
    except Exception:
        return None