Exception raised for invalid regular expressions. Attributes: msg: The unformatted error message pattern: The regular expression pattern pos: The index in the pattern where compilation failed (may be None) lineno: The line corresponding to pos (may be None)
| 21 | # should this really be here? |
| 22 | |
| 23 | class PatternError(Exception): |
| 24 | """Exception raised for invalid regular expressions. |
| 25 | |
| 26 | Attributes: |
| 27 | |
| 28 | msg: The unformatted error message |
| 29 | pattern: The regular expression pattern |
| 30 | pos: The index in the pattern where compilation failed (may be None) |
| 31 | lineno: The line corresponding to pos (may be None) |
| 32 | colno: The column corresponding to pos (may be None) |
| 33 | """ |
| 34 | |
| 35 | __module__ = 're' |
| 36 | |
| 37 | def __init__(self, msg, pattern=None, pos=None): |
| 38 | self.msg = msg |
| 39 | self.pattern = pattern |
| 40 | self.pos = pos |
| 41 | if pattern is not None and pos is not None: |
| 42 | msg = '%s at position %d' % (msg, pos) |
| 43 | if isinstance(pattern, str): |
| 44 | newline = '\n' |
| 45 | else: |
| 46 | newline = b'\n' |
| 47 | self.lineno = pattern.count(newline, 0, pos) + 1 |
| 48 | self.colno = pos - pattern.rfind(newline, 0, pos) |
| 49 | if newline in pattern: |
| 50 | msg = '%s (line %d, column %d)' % (msg, self.lineno, self.colno) |
| 51 | else: |
| 52 | self.lineno = self.colno = None |
| 53 | super().__init__(msg) |
| 54 | |
| 55 | |
| 56 | # Backward compatibility after renaming in 3.13 |
no outgoing calls
no test coverage detected
searching dependent graphs…