def where_clause_from_evtype(evtypes): cf = ua.ContentFilter() el = ua.ContentFilterElement() # operands can be ElementOperand, LiteralOperand, AttributeOperand, SimpleAttribute # Create a clause where the generate event type property EventType # must be a subtype of events in evtypes argument # the first operand is the attribute event type op = ua.SimpleAttributeOperand() # op.TypeDefinitionId = evtype.nodeid op.BrowsePath.append(ua.QualifiedName("EventType", 0)) op.AttributeId = ua.AttributeIds.Value el.FilterOperands.append(op) # now create a list of all subtypes we want to accept subtypes = [] for evtype in evtypes: subtypes += [st.nodeid for st in ua_utils.get_node_subtypes(evtype)] subtypes = list(set(subtypes)) # remove duplicates for subtypeid in subtypes: op = ua.LiteralOperand() op.Value = ua.Variant(subtypeid) el.FilterOperands.append(op) el.FilterOperator = ua.FilterOperator.InList cf.Elements.append(el) return cf
def where_clause_from_evtype(evtype): cf = ua.ContentFilter() el = ua.ContentFilterElement() # operands can be ElementOperand, LiteralOperand, AttributeOperand, SimpleAttribute op = ua.SimpleAttributeOperand() op.TypeDefinitionId = evtype.nodeid op.BrowsePath.append(ua.QualifiedName("EventType", 0)) op.AttributeId = ua.AttributeIds.Value el.FilterOperands.append(op) for subtypeid in [st.nodeid for st in get_node_subtypes(evtype)]: op = ua.LiteralOperand() op.Value = ua.Variant(subtypeid) el.FilterOperands.append(op) el.FilterOperator = ua.FilterOperator.InList cf.Elements.append(el) return cf
def test_where_clause(self): cf = ua.ContentFilter() el = ua.ContentFilterElement() op = ua.SimpleAttributeOperand() op.BrowsePath.append(ua.QualifiedName("property", 2)) el.FilterOperands.append(op) for i in range(10): op = ua.LiteralOperand() op.Value = ua.Variant(i) el.FilterOperands.append(op) el.FilterOperator = ua.FilterOperator.InList cf.Elements.append(el) wce = WhereClauseEvaluator(logging.getLogger(__name__), None, cf) ev = BaseEvent() ev._freeze = False ev.property = 3 self.assertTrue(wce.eval(ev))