Skip to content

Commit

Permalink
Run black after setting line-length
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Jul 5, 2023
1 parent 9ce0979 commit 17185b2
Show file tree
Hide file tree
Showing 40 changed files with 446 additions and 1,056 deletions.
4 changes: 1 addition & 3 deletions sigma/backends/test/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ class TextQueryTestBackend(TextQueryBackend):
re_escape: ClassVar[Tuple[str]] = ("/", "bar")

case_sensitive_match_expression = "{field} casematch {value}"
case_sensitive_startswith_expression: ClassVar[
str
] = "{field} startswith_cased {value}"
case_sensitive_startswith_expression: ClassVar[str] = "{field} startswith_cased {value}"
case_sensitive_endswith_expression: ClassVar[str] = "{field} endswith_cased {value}"
case_sensitive_contains_expression: ClassVar[str] = "{field} contains_cased {value}"

Expand Down
24 changes: 6 additions & 18 deletions sigma/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ class SigmaCollection:

rules: List[SigmaRule]
errors: List[SigmaError] = field(default_factory=list)
ids_to_rules: Dict[str, SigmaRule] = field(
init=False, repr=False, hash=False, compare=False
)
ids_to_rules: Dict[str, SigmaRule] = field(init=False, repr=False, hash=False, compare=False)

def __post_init__(self):
"""
Map rule identifiers to rules.
"""
self.ids_to_rules = {
str(rule.id): rule for rule in self.rules if rule.id is not None
}
self.ids_to_rules = {str(rule.id): rule for rule in self.rules if rule.id is not None}

@classmethod
def from_dicts(
Expand Down Expand Up @@ -70,9 +66,7 @@ def from_dicts(
action == "repeat"
): # add content of current rule to previous rule and parse it
prev_rule = deep_dict_update(prev_rule, rule)
parsed_rules.append(
SigmaRule.from_dict(prev_rule, collect_errors, source)
)
parsed_rules.append(SigmaRule.from_dict(prev_rule, collect_errors, source))
else:
exception = SigmaCollectionError(
f"Unknown Sigma collection action '{ action }' in rule { i }",
Expand All @@ -98,9 +92,7 @@ def from_yaml(
If the collect_errors parameters is set, exceptions are not raised while parsing but collected
in the errors property individually for each Sigma rule and the whole SigmaCollection.
"""
return cls.from_dicts(
list(yaml.safe_load_all(yaml_str)), collect_errors, source
)
return cls.from_dicts(list(yaml.safe_load_all(yaml_str)), collect_errors, source)

@classmethod
def resolve_paths(
Expand All @@ -118,19 +110,15 @@ def resolve_paths(
paths = ( # Recurse into directories if provided
path.glob(recursion_pattern) if path.is_dir() else (path,) for path in paths
)
return ( # Flatten the list
subpath for subpaths in paths for subpath in subpaths
)
return (subpath for subpaths in paths for subpath in subpaths) # Flatten the list

@classmethod
def load_ruleset(
cls,
inputs: List[Union[str, Path]],
collect_errors: bool = False,
on_beforeload: Optional[Callable[[Path], Optional[Path]]] = None,
on_load: Optional[
Callable[[Path, "SigmaCollection"], Optional["SigmaCollection"]]
] = None,
on_load: Optional[Callable[[Path, "SigmaCollection"], Optional["SigmaCollection"]]] = None,
recursion_pattern: str = "**/*.yml",
) -> "SigmaCollection":
"""
Expand Down
8 changes: 2 additions & 6 deletions sigma/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ class ConditionItem(ParentChainMixin, ABC):
source: Optional[SigmaRuleLocation] = field(default=None, compare=False)

@classmethod
def from_parsed(
cls, s: str, l: int, t: Union[ParseResults, list]
) -> "ConditionItem":
def from_parsed(cls, s: str, l: int, t: Union[ParseResults, list]) -> "ConditionItem":
"""Create condition object from parse result"""
if cls.arg_count == 1:
if cls.token_list:
Expand Down Expand Up @@ -185,9 +183,7 @@ def __post_init__(self):
self.cond_class = ConditionAND
self.pattern = self.args[1]

def resolve_referenced_detections(
self, detections: "sigma.rule.SigmaDetections"
) -> List[str]:
def resolve_referenced_detections(self, detections: "sigma.rule.SigmaDetections") -> List[str]:
"""
Resolve all detection identifiers referenced by the selector.
"""
Expand Down
Loading

0 comments on commit 17185b2

Please sign in to comment.