def METHOD_NAME(self, name, attr, value, result):
    # add a rule that matches any element with name `name` which has an
    # attribute `attr` equal to `value`
    rules = self.element_rules.setdefault(name, [])
    # element-and-attr rules have priority 1 (higher)
    rules.append(
        (1, (lambda attrs: attr in attrs and attrs[attr] == value), result)
    )
    # sort list on priority
    rules.sort(key=lambda t: t[0])