How to use the mwparserfromhell.smart_list.SmartList function in mwparserfromhell

To help you get started, we’ve selected a few mwparserfromhell examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github earwig / mwparserfromhell / tests / test_wikicode.py View on Github external
def test_nodes(self):
        """test getter/setter for the nodes attribute"""
        code = parse("Have a {{template}}")
        self.assertEqual(["Have a ", "{{template}}"], code.nodes)
        L1 = SmartList([Text("foobar"), Template(wraptext("abc"))])
        L2 = [Text("barfoo"), Template(wraptext("cba"))]
        L3 = "abc{{def}}"
        code.nodes = L1
        self.assertIs(L1, code.nodes)
        code.nodes = L2
        self.assertIs(L2, code.nodes)
        code.nodes = L3
        self.assertEqual(["abc", "{{def}}"], code.nodes)
        self.assertRaises(ValueError, setattr, code, "nodes", object)
github earwig / mwparserfromhell / tests / test_smart_list.py View on Github external
def test_parent_methods(self):
        """make sure SmartList's non-magic methods work, like append()"""
        self._test_list_methods(SmartList)
github earwig / mwparserfromhell / tests / test_smart_list.py View on Github external
        meth(lambda L: SmartList(list(L))[:])
        meth(lambda L: SmartList([999] + list(L))[1:])
github earwig / mwparserfromhell / tests / test_smart_list.py View on Github external
        meth(lambda L: SmartList([999] + list(L))[1:])
        meth(lambda L: SmartList(list(L) + [999])[:-1])
github earwig / mwparserfromhell / mwparserfromhell / parser / builder.py View on Github external
"""
        key = None
        showkey = False
        self._push()
        while self._tokens:
            token = self._tokens.pop()
            if isinstance(token, tokens.TemplateParamEquals):
                key = self._pop()
                showkey = True
                self._push()
            elif isinstance(token, (tokens.TemplateParamSeparator,
                                    tokens.TemplateClose)):
                self._tokens.append(token)
                value = self._pop()
                if key is None:
                    key = Wikicode(SmartList([Text(str(default))]))
                return Parameter(key, value, showkey)
            else:
                self._write(self._handle_token(token))
        raise ParserError("_handle_parameter() missed a close token")
github earwig / mwparserfromhell / mwparserfromhell / smart_list.py View on Github external
def __mul__(self, other):
        return SmartList(list(self) * other)
github earwig / mwparserfromhell / mwparserfromhell / utils.py View on Github external
if isinstance(value, Wikicode):
        return value
    elif isinstance(value, Node):
        return Wikicode(SmartList([value]))
    elif isinstance(value, str):
        return Parser().parse(value, context, skip_style_tags)
    elif isinstance(value, bytes):
        return Parser().parse(value.decode("utf8"), context, skip_style_tags)
    elif isinstance(value, int):
        return Parser().parse(str(value), context, skip_style_tags)
    elif value is None:
        return Wikicode(SmartList())
    elif hasattr(value, "read"):
        return parse_anything(value.read(), context, skip_style_tags)
    try:
        nodelist = SmartList()
        for item in value:
            nodelist += parse_anything(item, context, skip_style_tags).nodes
        return Wikicode(nodelist)
    except TypeError:
        error = "Needs string, Node, Wikicode, file, int, None, or iterable of these, but got {0}: {1}"
        raise ValueError(error.format(type(value).__name__, value))
github earwig / mwparserfromhell / mwparserfromhell / parser / build_stack.py View on Github external
def pop(self):
        return Wikicode(SmartList(self._stacks.pop()))
github earwig / mwparserfromhell / mwparserfromhell / smart_list.py View on Github external
def __radd__(self, other):
        return SmartList(other + list(self))