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:
Antonio Larrosa
2017-02-13 16:24:52 +01:00
parent b7c324b4de
commit 5daf2fecda

View File

@@ -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):