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

earwig / mwparserfromhell / 6080278913

05 Sep 2023 04:44AM UTC coverage: 99.136% (+0.04%) from 99.098%
6080278913

push

github

earwig
Fix pickling SmartLists (fixes #289)

23 of 23 new or added lines in 4 files covered. (100.0%)

2982 of 3008 relevant lines covered (99.14%)

6.9 hits per line

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

100.0
/src/mwparserfromhell/nodes/external_link.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
7✔
23
from ..utils import parse_anything
7✔
24

25
__all__ = ["ExternalLink"]
7✔
26

27

28
class ExternalLink(Node):
7✔
29
    """Represents an external link, like ``[http://example.com/ Example]``."""
30

31
    def __init__(self, url, title=None, brackets=True, suppress_space=False):
7✔
32
        super().__init__()
7✔
33
        self.url = url
7✔
34
        self.title = title
7✔
35
        self.brackets = brackets
7✔
36
        self.suppress_space = suppress_space
7✔
37

38
    def __str__(self):
7✔
39
        if self.brackets:
7✔
40
            if self.title is not None:
7✔
41
                if self.suppress_space is True:
7✔
42
                    return "[" + str(self.url) + str(self.title) + "]"
7✔
43
                return "[" + str(self.url) + " " + str(self.title) + "]"
7✔
44
            return "[" + str(self.url) + "]"
7✔
45
        return str(self.url)
7✔
46

47
    def __children__(self):
7✔
48
        yield self.url
7✔
49
        if self.title is not None:
7✔
50
            yield self.title
7✔
51

52
    def __strip__(self, **kwargs):
7✔
53
        if self.brackets:
7✔
54
            if self.title:
7✔
55
                return self.title.strip_code(**kwargs)
7✔
56
            return None
7✔
57
        return self.url.strip_code(**kwargs)
7✔
58

59
    def __showtree__(self, write, get, mark):
7✔
60
        if self.brackets:
7✔
61
            write("[")
7✔
62
        get(self.url)
7✔
63
        if self.title is not None:
7✔
64
            get(self.title)
7✔
65
        if self.brackets:
7✔
66
            write("]")
7✔
67

68
    @property
7✔
69
    def url(self):
6✔
70
        """The URL of the link target, as a :class:`.Wikicode` object."""
71
        return self._url
7✔
72

73
    @property
7✔
74
    def title(self):
6✔
75
        """The link title (if given), as a :class:`.Wikicode` object."""
76
        return self._title
7✔
77

78
    @property
7✔
79
    def brackets(self):
6✔
80
        """Whether to enclose the URL in brackets or display it straight."""
81
        return self._brackets
7✔
82

83
    @url.setter
7✔
84
    def url(self, value):
6✔
85
        # pylint: disable=import-outside-toplevel
86
        from ..parser import contexts
7✔
87

88
        self._url = parse_anything(value, contexts.EXT_LINK_URI)
7✔
89

90
    @title.setter
7✔
91
    def title(self, value):
6✔
92
        self._title = None if value is None else parse_anything(value)
7✔
93

94
    @brackets.setter
7✔
95
    def brackets(self, value):
6✔
96
        self._brackets = bool(value)
7✔
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