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

manoss96 / pregex / 4356417821

pending completion
4356417821

push

github

manoss96
add logo and funding

1625 of 1625 relevant lines covered (100.0%)

3.0 hits per line

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

100.0
/src/pregex/core/exceptions.py
1
class InvalidArgumentValueException(Exception):
3✔
2
    '''
3✔
3
    This exception is thrown whenever an argument of invalid value is provided.
4

5
    :param str message: The message that is to be displayed \
6
        along with the exception.
7
    '''
8

9
    def __init__(self, message: str):
3✔
10
        '''
11
        This exception is thrown whenever an argument of invalid value is provided.
12

13
        :param str message: The message that is to be displayed \
14
            along with the exception.
15
        '''
16
        super().__init__(message)
3✔
17

18

19
class InvalidArgumentTypeException(Exception):
3✔
20
    '''
3✔
21
    This exception is thrown whenever an argument of invalid type is provided.
22

23
    :param str message: The message that is to be displayed \
24
        along with the exception.
25
    '''
26

27
    def __init__(self, message: str):
3✔
28
        '''
29
        This exception is thrown whenever an argument of invalid type is provided.
30

31
        :param str message: The message that is to be displayed \
32
            along with the exception.
33
        '''
34
        super().__init__(message)
3✔
35

36

37
class NotEnoughArgumentsException(Exception):
3✔
38
    '''
3✔
39
    This exception is thrown whenever an insufficient amount \
40
    of arguments is provided.
41

42
    :param str message: The message that is to be displayed \
43
        along with the exception.
44
    '''
45

46
    def __init__(self, message: str):
3✔
47
        '''
48
        This exception is thrown whenever an insufficient amount \
49
        of arguments is provided.
50

51
        :param str message: The message that is to be displayed \
52
            along with the exception.
53
        '''
54
        super().__init__(message)
3✔
55

56

57
class InvalidCapturingGroupNameException(Exception):
3✔
58
    '''
3✔
59
    This exception is thrown whenever an invalid name \
60
    for a capturing group was provided.
61

62
    :param str name: The string type argument because of which this exception was thrown.
63
    '''
64

65
    def __init__(self, name: str):
3✔
66
        '''
67
        This exception is thrown whenever an invalid name \
68
        for a capturing group was provided.
69

70
        :param str name: The string type argument because of which this exception was thrown.
71
        '''
72
        super().__init__(f"Name \"{name}\" is not valid. A capturing group's " +
3✔
73
        "name must be an alphanumeric sequence that starts with a non-digit.")
74

75

76
class CannotBeNegatedException(Exception):
3✔
77
    '''
3✔
78
    This exception is thrown whenever one tries to negate class ``Any``.
79
    '''
80
    def __init__(self):
3✔
81
        '''
82
        This exception is thrown whenever one tries to negate class ``Any``.
83
        '''
84
        super().__init__(f"Class \"Any\" cannot be negated.")
3✔
85

86

87
class CannotBeUnionedException(Exception):
3✔
88
    '''
3✔
89
    This exception is thrown whenever one tries to union a class (or negated class) \
90
    either with a negated class (or regular class) or an object of different type.
91

92
    :param Pregex pre: The ``Pregex`` instance because of which this exception was thrown.
93
    :param bool are_both_classes: Indicates whether both ``Pregex`` instances are of \ 
94
        type ``__Class``.
95
    '''
96

97
    def __init__(self, pre, are_both_classes: bool):
3✔
98
        '''
99
        This exception is thrown whenever one tries to union a class (or negated class) \
100
        either with a negated class (or regular class) or an object of different type.
101

102
        :param Pregex pre: The ``Pregex`` instance because of which this exception was thrown.
103
        :param bool are_both_classes: Indicates whether both ``Pregex`` instances are of \ 
104
            type ``__Class``.
105
        '''
106
        m = f"Classes and negated classes cannot be unioned together." if are_both_classes \
3✔
107
            else f"Instance of type \"{type(pre).__name__}\" cannot be unioned with a class."
108
        super().__init__(m)
3✔
109

110

111
class CannotBeSubtractedException(Exception):
3✔
112
    '''
3✔
113
    This exception is thrown whenever one tries to subtract a class (or negated class) \
114
    either from a negated class (or regular class) or an object of different type.
115

116
    :param Pregex pre: The ``Pregex`` instance because of which this exception was thrown.
117
    :param bool are_both_classes: Indicates whether both ``Pregex`` instances are of type ``__Class``.
118
    '''
119

120
    def __init__(self, pre, are_both_classes: bool):
3✔
121
        '''
122
        This exception is thrown whenever one tries to subtract a class (or negated class) \
123
        either from a negated class (or regular class) or an object of different type.
124

125
        :param Pregex pre: The ``Pregex`` instance because of which this exception was thrown.
126
        :param bool are_both_classes: Indicates whether both ``Pregex`` instances are of type ``__Class``.
127
        '''
128
        m = f"Classes and negated classes cannot be subtracted from one another." if are_both_classes \
3✔
129
            else f"Instance of type \"{type(pre).__name__}\" cannot be subtracted from a class."
130
        super().__init__(m)
3✔
131

132

133
class GlobalWordCharSubtractionException(Exception):
3✔
134
    '''
3✔
135
    This exception is thrown whenever one tries to subtract from an instance of \
136
    either one of ``AnyWordChar`` or ``AnyButWordChar`` classes, for which parameter \
137
    "is_global" has been set to ``True``.
138

139
    :param AnyWordChar | AnyButWordChar pre: An instance of either one of the two classes.
140
    '''
141

142
    def __init__(self, pre):
3✔
143
        '''
144
        This exception is thrown whenever one tries to subtract from an instance of \
145
        either one of ``AnyWordChar`` or ``AnyButWordChar`` classes, for which parameter \
146
        "is_global" has been set to ``True``.
147

148
        :param AnyWordChar | AnyButWordChar pre: An instance of either one of the two classes.
149
        '''
150
        m = f"Cannot subtract from an instance of class \"{type(pre).__name__}\"" + \
3✔
151
             " for which parameter \"is_global\" has been set to \"True\"."
152
        super().__init__(m)
3✔
153

154

155
class EmptyClassException(Exception):
3✔
156
    '''
3✔
157
    This exception is thrown whenever one tries to subtract a class (or negated class) \
158
    from a class (or negated class) which results in an empty class.
159

160
    :param Pregex pre1: The ``Pregex`` instance because of which this exception was thrown.
161
    :param Pregex pre2: The ``Pregex`` instance because of which this exception was thrown.
162
    '''
163

164
    def __init__(self, pre1, pre2):
3✔
165
        '''
166
        This exception is thrown whenever one tries to subtract a class (or negated class) \
167
        from a class (or negated class) which results in an empty class.
168

169
        :param Pregex pre1: The ``Pregex`` instance because of which this exception was thrown.
170
        :param Pregex pre2: The ``Pregex`` instance because of which this exception was thrown.
171
        '''
172
        m = f"Cannot subtract class \"{pre2}\" from class \"{pre1}\"" \
3✔
173
            " as this results into an empty class."
174
        super().__init__(m)
3✔
175

176

177
class InvalidRangeException(Exception):
3✔
178
    '''
3✔
179
    This exception is thrown whenever there was provided a pair \
180
    of values ``start`` and ``end``, where ``start`` comes after ``end``.
181

182
    :param int start: The integer because of which this exception was thrown.
183
    :param int end: The integer because of which this exception was thrown.
184
    '''
185

186
    def __init__(self, start: int, end: int):
3✔
187
        '''
188
        This exception is thrown whenever there was provided a pair \
189
        of values ``start`` and ``end``, where ``start`` comes after ``end``.
190

191
        :param int start: The integer because of which this exception was thrown.
192
        :param int end: The integer because of which this exception was thrown.
193
        '''
194
        super().__init__(f"\"[{start}-{end}]\" is not a valid range.")
3✔
195

196

197
class CannotBeRepeatedException(Exception):
3✔
198
    '''
3✔
199
    This exception is thrown whenever an instance of a class \
200
    that is part of the ``assertions`` module is being quantified.
201

202
    :param __Assertion pre: The ``__Assertion`` instance because of which this exception was thrown.
203
    '''
204

205
    def __init__(self, pre):
3✔
206
        '''
207
        This exception is thrown whenever there is an attempt to \
208
        repeat a non-repeatable pattern.
209

210
        :param __Assertion pre: The ``__Assertion`` instance because of which this exception was thrown.
211
        '''
212
        m = f"Pattern \"{pre.get_pattern()}\" is non-repeatable."
3✔
213
        super().__init__(m)
3✔
214

215

216
class NonFixedWidthPatternException(Exception):
3✔
217
    '''
3✔
218
    This exception is thrown whenever a non-fixed-width pattern is being
219
    provided as lookbehind-pattern to either ``PrecededBy`` or ``NotPrecededBy``.
220

221
    :param __Lookaround lookbehind: The ``__Lookaround`` instance because of which this exception was thrown.
222
    :param Pregex pre: The ``Pregex`` instance because of which this exception was thrown.
223
    '''
224

225
    def __init__(self, lookbehind):
3✔
226
        '''
227
        This exception is thrown whenever a non-fixed-width pattern is being
228
        provided as lookbehind-pattern to either ``PrecededBy`` or ``NotPrecededBy``.
229

230
        :param __Lookaround lookbehind: The ``__Lookaround`` instance because of which this exception was thrown.
231
        '''
232
        m = f"Pattern '{lookbehind.get_pattern()}' cannot be used as a lookbehind"
3✔
233
        m += f" assertion pattern due to its variable length."
3✔
234
        super().__init__(m)
3✔
235

236

237
class EmptyNegativeAssertionException(Exception):
3✔
238
    '''
3✔
239
    This exception is thrown whenever the ``Empty`` pattern is provided
240
    as a negative assertion.
241
    '''
242

243
    def __init__(self):
3✔
244
        '''
245
        This exception is thrown whenever the ``Empty`` pattern is provided
246
        as a negative assertion.
247
        '''
248
        message = "The empty string can't be provided as a negative lookaround assertion pattern."
3✔
249
        super().__init__(message)
3✔
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