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

earwig / mwparserfromhell / 15949141982

28 Jun 2025 11:18PM UTC coverage: 98.886% (-0.3%) from 99.204%
15949141982

push

github

earwig
Fix a failing test

3106 of 3141 relevant lines covered (98.89%)

9.85 hits per line

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

98.33
/src/mwparserfromhell/nodes/external_link.py
1
# Copyright (C) 2012-2025 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
from __future__ import annotations
10✔
22

23
from collections.abc import Generator
10✔
24
from typing import TYPE_CHECKING, Any, Callable
10✔
25

26
from ..utils import parse_anything
10✔
27
from ._base import Node
10✔
28

29
if TYPE_CHECKING:
10✔
30
    from ..wikicode import Wikicode
×
31

32
__all__ = ["ExternalLink"]
10✔
33

34

35
class ExternalLink(Node):
10✔
36
    """Represents an external link, like ``[http://example.com/ Example]``."""
37

38
    def __init__(
10✔
39
        self,
40
        url: Any,
41
        title: Any = None,
42
        brackets: bool = True,
43
        suppress_space: bool = False,
44
    ):
45
        super().__init__()
10✔
46
        self.url = url
10✔
47
        self.title = title
10✔
48
        self.brackets = brackets
10✔
49
        self.suppress_space = suppress_space
10✔
50

51
    def __str__(self) -> str:
10✔
52
        if self.brackets:
10✔
53
            if self.title is not None:
10✔
54
                if self.suppress_space is True:
10✔
55
                    return "[" + str(self.url) + str(self.title) + "]"
10✔
56
                return "[" + str(self.url) + " " + str(self.title) + "]"
10✔
57
            return "[" + str(self.url) + "]"
10✔
58
        return str(self.url)
10✔
59

60
    def __children__(self) -> Generator[Wikicode, None, None]:
10✔
61
        yield self.url
10✔
62
        if self.title is not None:
10✔
63
            yield self.title
10✔
64

65
    def __strip__(self, **kwargs: Any) -> str | None:
10✔
66
        if self.brackets:
10✔
67
            if self.title:
10✔
68
                return self.title.strip_code(**kwargs)
10✔
69
            return None
10✔
70
        return self.url.strip_code(**kwargs)
10✔
71

72
    def __showtree__(
10✔
73
        self,
74
        write: Callable[[str], None],
75
        get: Callable[[Wikicode], None],
76
        mark: Callable[[], None],
77
    ) -> None:
78
        if self.brackets:
10✔
79
            write("[")
10✔
80
        get(self.url)
10✔
81
        if self.title is not None:
10✔
82
            get(self.title)
10✔
83
        if self.brackets:
10✔
84
            write("]")
10✔
85

86
    @property
10✔
87
    def url(self) -> Wikicode:
10✔
88
        """The URL of the link target, as a :class:`.Wikicode` object."""
89
        return self._url
10✔
90

91
    @url.setter
10✔
92
    def url(self, value: Any) -> None:
10✔
93
        # pylint: disable=import-outside-toplevel
94
        from ..parser import contexts
10✔
95

96
        self._url = parse_anything(value, contexts.EXT_LINK_URI)
10✔
97

98
    @property
10✔
99
    def title(self) -> Wikicode | None:
10✔
100
        """The link title (if given), as a :class:`.Wikicode` object."""
101
        return self._title
10✔
102

103
    @title.setter
10✔
104
    def title(self, value: Any) -> None:
10✔
105
        self._title = None if value is None else parse_anything(value)
10✔
106

107
    @property
10✔
108
    def brackets(self) -> bool:
10✔
109
        """Whether to enclose the URL in brackets or display it straight."""
110
        return self._brackets
10✔
111

112
    @brackets.setter
10✔
113
    def brackets(self, value: bool) -> None:
10✔
114
        self._brackets = bool(value)
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

© 2026 Coveralls, Inc