From ca175f02c7a80125fd7ae9b2371a3ec61ed9542c Mon Sep 17 00:00:00 2001 From: William Ballenthin Date: Mon, 6 Jul 2020 16:54:40 -0600 Subject: [PATCH] rules: factor out DESCRIPTION_SEPARATOR into a constant closes #87 --- capa/render/vverbose.py | 2 +- capa/rules.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/capa/render/vverbose.py b/capa/render/vverbose.py index df204745..7a703e96 100644 --- a/capa/render/vverbose.py +++ b/capa/render/vverbose.py @@ -82,7 +82,7 @@ def render_feature(ostream, match, feature, indent=0): ostream.write(rutils.bold2(feature[feature["type"]])) if "description" in feature: - ostream.write(" = ") + ostream.write(capa.rules.DESCRIPTION_SEPARATOR) ostream.write(feature["description"]) render_locations(ostream, match) diff --git a/capa/rules.py b/capa/rules.py index 4ca42553..305c4a95 100644 --- a/capa/rules.py +++ b/capa/rules.py @@ -207,16 +207,23 @@ def parse_feature(key): raise InvalidRule("unexpected statement: %s" % key) +# this is the separator between a feature value and its description +# when using the inline description syntax, like: +# +# number: 42 = ENUM_FAVORITE_NUMBER +DESCRIPTION_SEPARATOR = " = " + + def parse_description(s, value_type, description=None): """ s can be an int or a string """ - if value_type != "string" and isinstance(s, six.string_types) and " = " in s: + if value_type != "string" and isinstance(s, six.string_types) and DESCRIPTION_SEPARATOR in s: if description: raise InvalidRule( - 'unexpected value: "%s", only one description allowed (inline description with ` = `)' % s + 'unexpected value: "%s", only one description allowed (inline description with `%s`)' % (s, DESCRIPTION_SEPARATOR) ) - value, _, description = s.rpartition(" = ") + value, _, description = s.rpartition(DESCRIPTION_SEPARATOR) if description == "": raise InvalidRule('unexpected value: "%s", description cannot be empty' % s) else: