From 5daf2fecda9d06c96824ed322487fcf40f105768 Mon Sep 17 00:00:00 2001 From: Antonio Larrosa Date: Mon, 13 Feb 2017 16:24:52 +0100 Subject: [PATCH] Fix PEP8 issues and rename text to haystack everywhere The text variable was renamed to haystack except in some lines. This commit fixes this and also fixes some coding style issues. --- picard/script.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/picard/script.py b/picard/script.py index 54ad48131..487d99b52 100644 --- a/picard/script.py +++ b/picard/script.py @@ -388,29 +388,32 @@ def func_in(parser, text, needle): def func_inmulti(parser, haystack, needle, separator=MULTI_VALUED_JOINER): - """Searches for ``needle`` in ``haystack``, supporting a list variable for ``haystack``. - If a string is used instead, then a ``separator`` can be used to split it. - In both cases, it returns true if the resulting list contains ``needle``.""" + """Searches for ``needle`` in ``haystack``, supporting a list variable for + ``haystack``. If a string is used instead, then a ``separator`` can be + used to split it. In both cases, it returns true if the resulting list + contains ``needle``.""" needle = needle.eval(parser) - if type(text)==ScriptExpression and len(text)==1 and type(text[0])==ScriptVariable: - text=text[0] - if type(text)==ScriptVariable: - if text.name.startswith(u"_"): - name = u"~" + text.name[1:] - else: - name = text.name - values=parser.context.getall(name) + if (isinstance(haystack, ScriptExpression) and + len(haystack) == 1 and + isinstance(haystack[0], ScriptVariable)): + haystack = haystack[0] - if needle in values: - return "1" + if isinstance(haystack, ScriptVariable): + if haystack.name.startswith(u"_"): + name = u"~" + haystack.name[1:] else: - return "" + name = haystack.name + values = parser.context.getall(name) + + return func_in(parser, values, needle) # I'm not sure if it is actually possible to continue in this code path, # but just in case, it's better to have a fallback to correct behaviour - text=text.eval(parser) - return func_in(parser, text.split(separator) if separator else [text], needle) + haystack = haystack.eval(parser) + return func_in(parser, + haystack.split(separator) if separator else [haystack], + needle) def func_rreplace(parser, text, old, new):