Parse the backtrace string into a list of (filename, lineno, func). Parameters ---------- backtrace The backtrace string. Returns ------- result The list of (filename, lineno, func)
(backtrace: str)
| 29 | |
| 30 | |
| 31 | def _parse_backtrace(backtrace: str) -> list[tuple[str, int, str]]: |
| 32 | """Parse the backtrace string into a list of (filename, lineno, func). |
| 33 | |
| 34 | Parameters |
| 35 | ---------- |
| 36 | backtrace |
| 37 | The backtrace string. |
| 38 | |
| 39 | Returns |
| 40 | ------- |
| 41 | result |
| 42 | The list of (filename, lineno, func) |
| 43 | |
| 44 | """ |
| 45 | pattern = r'File "(.+?)", line (\d+), in (.+)' |
| 46 | result = [] |
| 47 | for line in backtrace.split("\n"): |
| 48 | match = re.match(pattern, line.strip()) |
| 49 | if match: |
| 50 | try: |
| 51 | filename = match.group(1) |
| 52 | lineno = int(match.group(2)) |
| 53 | func = match.group(3) |
| 54 | result.append((filename, lineno, func)) |
| 55 | except ValueError: |
| 56 | pass |
| 57 | return result |
| 58 | |
| 59 | |
| 60 | class TracebackManager: |
no test coverage detected