diff --git a/stix2/pattern_visitor.py b/stix2/pattern_visitor.py index 94c8559..16e4d3c 100644 --- a/stix2/pattern_visitor.py +++ b/stix2/pattern_visitor.py @@ -4,8 +4,9 @@ import inspect from antlr4 import CommonTokenStream, InputStream import six from stix2patterns.grammars.STIXPatternLexer import STIXPatternLexer -from stix2patterns.grammars.STIXPatternParser import (STIXPatternParser, - TerminalNode) +from stix2patterns.grammars.STIXPatternParser import ( + STIXPatternParser, TerminalNode, +) from stix2patterns.grammars.STIXPatternVisitor import STIXPatternVisitor from stix2patterns.validator import STIXPatternErrorListener @@ -149,25 +150,35 @@ class STIXPatternVisitorForSTIX2(STIXPatternVisitor): children = self.visitChildren(ctx) operator = children[1].symbol.type negated = operator != STIXPatternParser.EQ - return self.instantiate("EqualityComparisonExpression", children[0], children[3 if len(children) > 3 else 2], - negated) + return self.instantiate( + "EqualityComparisonExpression", children[0], children[3 if len(children) > 3 else 2], + negated, + ) # Visit a parse tree produced by STIXPatternParser#propTestOrder. def visitPropTestOrder(self, ctx): children = self.visitChildren(ctx) operator = children[1].symbol.type if operator == STIXPatternParser.GT: - return self.instantiate("GreaterThanComparisonExpression", children[0], - children[3 if len(children) > 3 else 2], False) + return self.instantiate( + "GreaterThanComparisonExpression", children[0], + children[3 if len(children) > 3 else 2], False, + ) elif operator == STIXPatternParser.LT: - return self.instantiate("LessThanComparisonExpression", children[0], - children[3 if len(children) > 3 else 2], False) + return self.instantiate( + "LessThanComparisonExpression", children[0], + children[3 if len(children) > 3 else 2], False, + ) elif operator == STIXPatternParser.GE: - return self.instantiate("GreaterThanEqualComparisonExpression", children[0], - children[3 if len(children) > 3 else 2], False) + return self.instantiate( + "GreaterThanEqualComparisonExpression", children[0], + children[3 if len(children) > 3 else 2], False, + ) elif operator == STIXPatternParser.LE: - return self.instantiate("LessThanEqualComparisonExpression", children[0], - children[3 if len(children) > 3 else 2], False) + return self.instantiate( + "LessThanEqualComparisonExpression", children[0], + children[3 if len(children) > 3 else 2], False, + ) # Visit a parse tree produced by STIXPatternParser#propTestSet. def visitPropTestSet(self, ctx): @@ -182,8 +193,10 @@ class STIXPatternVisitorForSTIX2(STIXPatternVisitor): # Visit a parse tree produced by STIXPatternParser#propTestRegex. def visitPropTestRegex(self, ctx): children = self.visitChildren(ctx) - return self.instantiate("MatchesComparisonExpression", children[0], children[3 if len(children) > 3 else 2], - False) + return self.instantiate( + "MatchesComparisonExpression", children[0], children[3 if len(children) > 3 else 2], + False, + ) # Visit a parse tree produced by STIXPatternParser#propTestIsSubset. def visitPropTestIsSubset(self, ctx): diff --git a/stix2/test/v20/test_pattern_expressions.py b/stix2/test/v20/test_pattern_expressions.py index ac98489..3dc7cde 100644 --- a/stix2/test/v20/test_pattern_expressions.py +++ b/stix2/test/v20/test_pattern_expressions.py @@ -513,9 +513,11 @@ def test_parsing_comparison_expression(): def test_parsing_qualified_expression(): patt_obj = create_pattern_object( - "[network-traffic:dst_ref.type = 'domain-name' AND network-traffic:dst_ref.value = 'example.com'] REPEATS 5 TIMES WITHIN 1800 SECONDS") + "[network-traffic:dst_ref.type = 'domain-name' AND network-traffic:dst_ref.value = 'example.com'] REPEATS 5 TIMES WITHIN 1800 SECONDS", + ) assert str( - patt_obj) == "[network-traffic:dst_ref.type = 'domain-name' AND network-traffic:dst_ref.value = 'example.com'] REPEATS 5 TIMES WITHIN 1800 SECONDS" + patt_obj, + ) == "[network-traffic:dst_ref.type = 'domain-name' AND network-traffic:dst_ref.value = 'example.com'] REPEATS 5 TIMES WITHIN 1800 SECONDS" def test_list_constant(): diff --git a/stix2/test/v21/test_pattern_expressions.py b/stix2/test/v21/test_pattern_expressions.py index ac98489..3dc7cde 100644 --- a/stix2/test/v21/test_pattern_expressions.py +++ b/stix2/test/v21/test_pattern_expressions.py @@ -513,9 +513,11 @@ def test_parsing_comparison_expression(): def test_parsing_qualified_expression(): patt_obj = create_pattern_object( - "[network-traffic:dst_ref.type = 'domain-name' AND network-traffic:dst_ref.value = 'example.com'] REPEATS 5 TIMES WITHIN 1800 SECONDS") + "[network-traffic:dst_ref.type = 'domain-name' AND network-traffic:dst_ref.value = 'example.com'] REPEATS 5 TIMES WITHIN 1800 SECONDS", + ) assert str( - patt_obj) == "[network-traffic:dst_ref.type = 'domain-name' AND network-traffic:dst_ref.value = 'example.com'] REPEATS 5 TIMES WITHIN 1800 SECONDS" + patt_obj, + ) == "[network-traffic:dst_ref.type = 'domain-name' AND network-traffic:dst_ref.value = 'example.com'] REPEATS 5 TIMES WITHIN 1800 SECONDS" def test_list_constant():