main: fix rule content decoding

This commit is contained in:
Willi Ballenthin
2023-01-20 15:01:05 +01:00
parent e644775ad1
commit e09d35bbb9
2 changed files with 3 additions and 3 deletions

View File

@@ -620,7 +620,7 @@ def get_rules(rule_paths: List[str], disable_progress=False) -> RuleSet:
for path, content in pbar(zip(rule_file_paths, rule_contents), desc="parsing ", unit=" rules"):
try:
rule = capa.rules.Rule.from_yaml(content)
rule = capa.rules.Rule.from_yaml(content.decode("utf-8"))
except capa.rules.InvalidRule:
raise
else:

View File

@@ -743,7 +743,7 @@ class Rule:
return self.statement.evaluate(features, short_circuit=short_circuit)
@classmethod
def from_dict(cls, d, definition) -> "Rule":
def from_dict(cls, d: Dict[str, Any], definition: str) -> "Rule":
meta = d["rule"]["meta"]
name = meta["name"]
# if scope is not specified, default to function scope.
@@ -813,7 +813,7 @@ class Rule:
return y
@classmethod
def from_yaml(cls, s, use_ruamel=False) -> "Rule":
def from_yaml(cls, s: str, use_ruamel=False) -> "Rule":
if use_ruamel:
# ruamel enables nice formatting and doc roundtripping with comments
doc = cls._get_ruamel_yaml_parser().load(s)