Show More
@@ -1,29 +1,40 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 |
|
2 | |||
3 | # Filters traceback lines from stdin. |
|
3 | # Filters traceback lines from stdin. | |
4 |
|
4 | |||
5 | from __future__ import absolute_import, print_function |
|
5 | from __future__ import absolute_import, print_function | |
6 |
|
6 | |||
|
7 | import io | |||
7 | import sys |
|
8 | import sys | |
8 |
|
9 | |||
|
10 | if sys.version_info[0] >= 3: | |||
|
11 | # Prevent \r from being inserted on Windows. | |||
|
12 | sys.stdout = io.TextIOWrapper( | |||
|
13 | sys.stdout.buffer, | |||
|
14 | sys.stdout.encoding, | |||
|
15 | sys.stdout.errors, | |||
|
16 | newline="\n", | |||
|
17 | line_buffering=sys.stdout.line_buffering, | |||
|
18 | ) | |||
|
19 | ||||
9 | state = 'none' |
|
20 | state = 'none' | |
10 |
|
21 | |||
11 | for line in sys.stdin: |
|
22 | for line in sys.stdin: | |
12 | if state == 'none': |
|
23 | if state == 'none': | |
13 | if line.startswith('Traceback '): |
|
24 | if line.startswith('Traceback '): | |
14 | state = 'tb' |
|
25 | state = 'tb' | |
15 |
|
26 | |||
16 | elif state == 'tb': |
|
27 | elif state == 'tb': | |
17 | if line.startswith(' File '): |
|
28 | if line.startswith(' File '): | |
18 | state = 'file' |
|
29 | state = 'file' | |
19 | continue |
|
30 | continue | |
20 |
|
31 | |||
21 | elif not line.startswith(' '): |
|
32 | elif not line.startswith(' '): | |
22 | state = 'none' |
|
33 | state = 'none' | |
23 |
|
34 | |||
24 | elif state == 'file': |
|
35 | elif state == 'file': | |
25 | # Ignore lines after " File " |
|
36 | # Ignore lines after " File " | |
26 | state = 'tb' |
|
37 | state = 'tb' | |
27 | continue |
|
38 | continue | |
28 |
|
39 | |||
29 | print(line, end='') |
|
40 | print(line, end='') |
General Comments 0
You need to be logged in to leave comments.
Login now