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

earwig / mwparserfromhell / 10014163542

19 Jul 2024 08:49PM CUT 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

95.12
/src/mwparserfromhell/string_mixin.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
This module contains the :class:`.StringMixIn` type, which implements the
23
interface for the ``str`` type in a dynamic manner.
24
"""
25

26
from sys import getdefaultencoding
10✔
27

28
__all__ = ["StringMixIn"]
10✔
29

30

31
def inheritdoc(method):
10✔
32
    """Set __doc__ of *method* to __doc__ of *method* in its parent class.
33

34
    Since this is used on :class:`.StringMixIn`, the "parent class" used is
35
    ``str``. This function can be used as a decorator.
36
    """
37
    method.__doc__ = getattr(str, method.__name__).__doc__
×
38
    return method
×
39

40

41
class StringMixIn:
10✔
42
    """Implement the interface for ``str`` in a dynamic manner.
43

44
    To use this class, inherit from it and override the :meth:`__str__` method
45
    to return the string representation of the object. The various string
46
    methods will operate on the value of :meth:`__str__` instead of the
47
    immutable ``self`` like the regular ``str`` type.
48
    """
49

50
    def __str__(self):
10✔
51
        raise NotImplementedError()
52

53
    def __bytes__(self):
10✔
54
        return bytes(self.__str__(), getdefaultencoding())
10✔
55

56
    def __repr__(self):
10✔
57
        return repr(self.__str__())
10✔
58

59
    def __lt__(self, other):
10✔
60
        return self.__str__() < other
10✔
61

62
    def __le__(self, other):
10✔
63
        return self.__str__() <= other
10✔
64

65
    def __eq__(self, other):
10✔
66
        return self.__str__() == other
10✔
67

68
    def __ne__(self, other):
10✔
69
        return self.__str__() != other
10✔
70

71
    def __gt__(self, other):
10✔
72
        return self.__str__() > other
10✔
73

74
    def __ge__(self, other):
10✔
75
        return self.__str__() >= other
10✔
76

77
    def __bool__(self):
10✔
78
        return bool(self.__str__())
10✔
79

80
    def __len__(self):
10✔
81
        return len(self.__str__())
10✔
82

83
    def __iter__(self):
10✔
84
        yield from self.__str__()
10✔
85

86
    def __getitem__(self, key):
10✔
87
        return self.__str__()[key]
10✔
88

89
    def __reversed__(self):
10✔
90
        return reversed(self.__str__())
10✔
91

92
    def __contains__(self, item):
10✔
93
        return str(item) in self.__str__()
10✔
94

95
    def __getattr__(self, attr):
10✔
96
        if not hasattr(str, attr):
10✔
97
            raise AttributeError(
10✔
98
                "{!r} object has no attribute {!r}".format(type(self).__name__, attr)
99
            )
100
        return getattr(self.__str__(), attr)
10✔
101

102
    maketrans = str.maketrans  # Static method can't rely on __getattr__
10✔
103

104

105
del inheritdoc
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