From 6c283b7b8d0279bd8a2aaa560352b58345950b17 Mon Sep 17 00:00:00 2001 From: Michael Chisholm Date: Wed, 23 Sep 2020 15:43:21 -0400 Subject: [PATCH] Simplify brackets_check(): reimplement without the generator. --- stix2patterns/helpers.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/stix2patterns/helpers.py b/stix2patterns/helpers.py index d98631c..177890d 100644 --- a/stix2patterns/helpers.py +++ b/stix2patterns/helpers.py @@ -11,13 +11,12 @@ def brackets_check(pattern): :return: True if the pattern had its brackets; False if not """ if isinstance(pattern, six.string_types): - # the non-whitespace chars - non_ws_chars = (c for c in pattern if not c.isspace()) - # There can be an arbitrary number of open parens first... skip over those - c = next(non_ws_chars, None) - while c == "(": - c = next(non_ws_chars, None) + # There can be an arbitrary number of open parens first... skip over + # those + for c in pattern: + if c != "(" and not c.isspace(): + break if c == "[": result = True