def METHOD_NAME(self, context):
    context_rules = []
    for ctx_key, ctx_value in context.items():
        if ctx_key == exts.MDATA_COMMAND_CONTEXT_TYPE:
            context_type = (
                exts.MDATA_COMMAND_CONTEXT_ANY_SEP
                if ctx_value == exts.MDATA_COMMAND_CONTEXT_ANY
                else exts.MDATA_COMMAND_CONTEXT_ALL_SEP
            )
            continue
        if isinstance(ctx_value, str):
            ctx_value = [ctx_value]
        key = ctx_key.lower()
        condition = ""
        # all
        if key == exts.MDATA_COMMAND_CONTEXT_ALL \
                or key == exts.MDATA_COMMAND_CONTEXT_NOTALL:
            condition = exts.MDATA_COMMAND_CONTEXT_ALL_SEP
        # any
        elif key == exts.MDATA_COMMAND_CONTEXT_ANY \
                or key == exts.MDATA_COMMAND_CONTEXT_NOTANY:
            condition = exts.MDATA_COMMAND_CONTEXT_ANY_SEP
        # except
        elif key == exts.MDATA_COMMAND_CONTEXT_EXACT \
                or key == exts.MDATA_COMMAND_CONTEXT_NOTEXACT:
            condition = exts.MDATA_COMMAND_CONTEXT_EXACT_SEP
        context = condition.join(
            [x for x in ctx_value if isinstance(x, str)]
            )
        formatted_rule = \
            exts.MDATA_COMMAND_CONTEXT_RULE.format(rule=context)
        if key.startswith(exts.MDATA_COMMAND_CONTEXT_NOT):
            formatted_rule = "!" + formatted_rule
        context_rules.append(formatted_rule)
    return context_rules