pre-commit formatting changes
parent
f12cc82d8a
commit
7d84c63e8e
|
@ -4,8 +4,9 @@ import inspect
|
||||||
from antlr4 import CommonTokenStream, InputStream
|
from antlr4 import CommonTokenStream, InputStream
|
||||||
import six
|
import six
|
||||||
from stix2patterns.grammars.STIXPatternLexer import STIXPatternLexer
|
from stix2patterns.grammars.STIXPatternLexer import STIXPatternLexer
|
||||||
from stix2patterns.grammars.STIXPatternParser import (STIXPatternParser,
|
from stix2patterns.grammars.STIXPatternParser import (
|
||||||
TerminalNode)
|
STIXPatternParser, TerminalNode,
|
||||||
|
)
|
||||||
from stix2patterns.grammars.STIXPatternVisitor import STIXPatternVisitor
|
from stix2patterns.grammars.STIXPatternVisitor import STIXPatternVisitor
|
||||||
from stix2patterns.validator import STIXPatternErrorListener
|
from stix2patterns.validator import STIXPatternErrorListener
|
||||||
|
|
||||||
|
@ -149,25 +150,35 @@ class STIXPatternVisitorForSTIX2(STIXPatternVisitor):
|
||||||
children = self.visitChildren(ctx)
|
children = self.visitChildren(ctx)
|
||||||
operator = children[1].symbol.type
|
operator = children[1].symbol.type
|
||||||
negated = operator != STIXPatternParser.EQ
|
negated = operator != STIXPatternParser.EQ
|
||||||
return self.instantiate("EqualityComparisonExpression", children[0], children[3 if len(children) > 3 else 2],
|
return self.instantiate(
|
||||||
negated)
|
"EqualityComparisonExpression", children[0], children[3 if len(children) > 3 else 2],
|
||||||
|
negated,
|
||||||
|
)
|
||||||
|
|
||||||
# Visit a parse tree produced by STIXPatternParser#propTestOrder.
|
# Visit a parse tree produced by STIXPatternParser#propTestOrder.
|
||||||
def visitPropTestOrder(self, ctx):
|
def visitPropTestOrder(self, ctx):
|
||||||
children = self.visitChildren(ctx)
|
children = self.visitChildren(ctx)
|
||||||
operator = children[1].symbol.type
|
operator = children[1].symbol.type
|
||||||
if operator == STIXPatternParser.GT:
|
if operator == STIXPatternParser.GT:
|
||||||
return self.instantiate("GreaterThanComparisonExpression", children[0],
|
return self.instantiate(
|
||||||
children[3 if len(children) > 3 else 2], False)
|
"GreaterThanComparisonExpression", children[0],
|
||||||
|
children[3 if len(children) > 3 else 2], False,
|
||||||
|
)
|
||||||
elif operator == STIXPatternParser.LT:
|
elif operator == STIXPatternParser.LT:
|
||||||
return self.instantiate("LessThanComparisonExpression", children[0],
|
return self.instantiate(
|
||||||
children[3 if len(children) > 3 else 2], False)
|
"LessThanComparisonExpression", children[0],
|
||||||
|
children[3 if len(children) > 3 else 2], False,
|
||||||
|
)
|
||||||
elif operator == STIXPatternParser.GE:
|
elif operator == STIXPatternParser.GE:
|
||||||
return self.instantiate("GreaterThanEqualComparisonExpression", children[0],
|
return self.instantiate(
|
||||||
children[3 if len(children) > 3 else 2], False)
|
"GreaterThanEqualComparisonExpression", children[0],
|
||||||
|
children[3 if len(children) > 3 else 2], False,
|
||||||
|
)
|
||||||
elif operator == STIXPatternParser.LE:
|
elif operator == STIXPatternParser.LE:
|
||||||
return self.instantiate("LessThanEqualComparisonExpression", children[0],
|
return self.instantiate(
|
||||||
children[3 if len(children) > 3 else 2], False)
|
"LessThanEqualComparisonExpression", children[0],
|
||||||
|
children[3 if len(children) > 3 else 2], False,
|
||||||
|
)
|
||||||
|
|
||||||
# Visit a parse tree produced by STIXPatternParser#propTestSet.
|
# Visit a parse tree produced by STIXPatternParser#propTestSet.
|
||||||
def visitPropTestSet(self, ctx):
|
def visitPropTestSet(self, ctx):
|
||||||
|
@ -182,8 +193,10 @@ class STIXPatternVisitorForSTIX2(STIXPatternVisitor):
|
||||||
# Visit a parse tree produced by STIXPatternParser#propTestRegex.
|
# Visit a parse tree produced by STIXPatternParser#propTestRegex.
|
||||||
def visitPropTestRegex(self, ctx):
|
def visitPropTestRegex(self, ctx):
|
||||||
children = self.visitChildren(ctx)
|
children = self.visitChildren(ctx)
|
||||||
return self.instantiate("MatchesComparisonExpression", children[0], children[3 if len(children) > 3 else 2],
|
return self.instantiate(
|
||||||
False)
|
"MatchesComparisonExpression", children[0], children[3 if len(children) > 3 else 2],
|
||||||
|
False,
|
||||||
|
)
|
||||||
|
|
||||||
# Visit a parse tree produced by STIXPatternParser#propTestIsSubset.
|
# Visit a parse tree produced by STIXPatternParser#propTestIsSubset.
|
||||||
def visitPropTestIsSubset(self, ctx):
|
def visitPropTestIsSubset(self, ctx):
|
||||||
|
|
|
@ -513,9 +513,11 @@ def test_parsing_comparison_expression():
|
||||||
|
|
||||||
def test_parsing_qualified_expression():
|
def test_parsing_qualified_expression():
|
||||||
patt_obj = create_pattern_object(
|
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(
|
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():
|
def test_list_constant():
|
||||||
|
|
|
@ -513,9 +513,11 @@ def test_parsing_comparison_expression():
|
||||||
|
|
||||||
def test_parsing_qualified_expression():
|
def test_parsing_qualified_expression():
|
||||||
patt_obj = create_pattern_object(
|
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(
|
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():
|
def test_list_constant():
|
||||||
|
|
Loading…
Reference in New Issue