• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

earwig / mwparserfromhell / 10014163542

19 Jul 2024 08:49PM UTC coverage: 99.201% (-0.002%) from 99.203%
10014163542

Pull #326

github

web-flow
Merge 8c23031f1 into 4e73af2fa
Pull Request #326: Make fallthrough explicit in tok_parse.c

2979 of 3003 relevant lines covered (99.2%)

9.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/mwparserfromhell/nodes/argument.py
1
# Copyright (C) 2012-2020 Ben Kurtovic <ben.kurtovic@gmail.com>
2
#
3
# Permission is hereby granted, free of charge, to any person obtaining a copy
4
# of this software and associated documentation files (the "Software"), to deal
5
# in the Software without restriction, including without limitation the rights
6
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
# copies of the Software, and to permit persons to whom the Software is
8
# furnished to do so, subject to the following conditions:
9
#
10
# The above copyright notice and this permission notice shall be included in
11
# all copies or substantial portions of the Software.
12
#
13
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
# SOFTWARE.
20

21

22
from ._base import Node
10✔
23
from ..utils import parse_anything
10✔
24

25
__all__ = ["Argument"]
10✔
26

27

28
class Argument(Node):
10✔
29
    """Represents a template argument substitution, like ``{{{foo}}}``."""
30

31
    def __init__(self, name, default=None):
10✔
32
        super().__init__()
10✔
33
        self.name = name
10✔
34
        self.default = default
10✔
35

36
    def __str__(self):
10✔
37
        start = "{{{" + str(self.name)
10✔
38
        if self.default is not None:
10✔
39
            return start + "|" + str(self.default) + "}}}"
10✔
40
        return start + "}}}"
10✔
41

42
    def __children__(self):
10✔
43
        yield self.name
10✔
44
        if self.default is not None:
10✔
45
            yield self.default
10✔
46

47
    def __strip__(self, **kwargs):
10✔
48
        if self.default is not None:
10✔
49
            return self.default.strip_code(**kwargs)
10✔
50
        return None
10✔
51

52
    def __showtree__(self, write, get, mark):
10✔
53
        write("{{{")
10✔
54
        get(self.name)
10✔
55
        if self.default is not None:
10✔
56
            write("    | ")
10✔
57
            mark()
10✔
58
            get(self.default)
10✔
59
        write("}}}")
10✔
60

61
    @property
10✔
62
    def name(self):
10✔
63
        """The name of the argument to substitute."""
64
        return self._name
10✔
65

66
    @property
10✔
67
    def default(self):
10✔
68
        """The default value to substitute if none is passed.
69

70
        This will be ``None`` if the argument wasn't defined with one. The
71
        MediaWiki parser handles this by rendering the argument itself in the
72
        result, complete braces. To have the argument render as nothing, set
73
        default to ``""`` (``{{{arg}}}`` vs. ``{{{arg|}}}``).
74
        """
75
        return self._default
10✔
76

77
    @name.setter
10✔
78
    def name(self, value):
10✔
79
        self._name = parse_anything(value)
10✔
80

81
    @default.setter
10✔
82
    def default(self, default):
10✔
83
        if default is None:
10✔
84
            self._default = None
10✔
85
        else:
86
            self._default = parse_anything(default)
10✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc