mirror of
https://github.com/fergalmoran/picard.git
synced 2026-02-28 10:33:59 +00:00
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.
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user