-
Notifications
You must be signed in to change notification settings - Fork 1
/
epyfilter.py
235 lines (184 loc) · 6.4 KB
/
epyfilter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
# this script filters output from epydoc and similar scripts
# according to regexps.
# It can't be done inside gendoc.py by replacing stderr, because epydoc
# does stderr replacement of its own
import re
# we filter out multi-line blocks by looking for start markers and
# corresponding stop markers.
# Each start marker can have multiple stop markers. Each stop marker can
# have multiple blocks that need filtering out.
import sys
debug = sys.stdout.write
# comment this line if you want to see debug output
debug = lambda x: x
class REO:
flags = 0
def __init__(self, pattern):
"""
@param pattern: the regexp pattern to match
@type pattern: str
If pattern is None, it is meant to match anything, even empty.
"""
if pattern:
self.reo = re.compile(pattern, self.flags)
else:
self.reo = None
# for debugging
self._pattern = pattern
class Block(REO):
flags = re.MULTILINE
class Stop(REO):
blocks = None
def __init__(self, pattern, blocks=None):
REO.__init__(self, pattern)
if blocks:
for b in blocks:
self.addBlock(b)
def addBlock(self, block):
if not self.blocks:
self.blocks = []
self.blocks.append(block)
class Start(REO):
stops = None
def __init__(self, pattern, stops=None):
REO.__init__(self, pattern)
if stops:
for s in stops:
self.addStop(s)
def addStop(self, stop):
if not self.stops:
self.stops = []
self.stops.append(stop)
class Filter:
def __init__(self, stdin, stdout):
self._stdin = stdin
self._stdout = stdout
self._starts = []
self._reos = []
self._multilines = []
self._buffer = ''
def addRegExpObject(self, reo):
"""
Add a regexp for text to filter out.
"""
self._reos.append(reo)
def addStart(self, start):
self._starts.append(start)
def start(self):
while True:
line = self._stdin.readline()
# handle EOF
if line == '':
break
foundMatch = False
for reo in self._reos:
if re.match(reo, line):
foundMatch = True
continue
if foundMatch:
continue
self._buffer += line
for start in self._starts:
if start.reo.match(line):
debug("found start: %s" % line)
# we're in a matching start block, look for the stop marker
stopFound = False
blockFound = False
lines = ''
while not stopFound:
line = self._stdin.readline()
# handle EOF
if line == '':
break
# see if any stop matches
for stop in start.stops:
if stop.reo.match(line):
stopFound = True
debug("found stop: %s" % line)
debug("have block: %s" % lines)
break
if not stopFound:
lines += line
# now that a stop is found, see if we can match a block
# to filter out
for block in stop.blocks:
if block.reo == None or block.reo.match(lines):
debug("found block: %s" % lines)
self._buffer = ''
blockFound = True
# if no block was found, we should append the
# suspected block lines and the stop line
if not blockFound:
self._buffer += lines + line
self._stdout.write(self._buffer)
self._stdout.flush()
self._buffer = ''
def main():
# allow external python module to define/override starts and singles
global starts, singles
starts = None
singles = None
if len(sys.argv) > 1:
execfile(sys.argv[1])
else:
starts = [
Start('^=+$', [
Stop('^$', [
Block('In gtk'),
Block('In gobject'),
Block('In __builtin__'),
# don't catch only /twisted/ since we have a twisted dir too
Block('.*/twisted/spread'),
Block('.*/twisted/trial'),
])
]),
Start('- TestResult', [
Stop('TestCase.run\)$', [
Block('from twisted.trial'),
])
]),
Start('.*\/ihooks.py.*DeprecationWarning: The sre module', [
Stop('.*return imp.load_source\(name, filename, file\)', [
Block(None),
])
]),
Start('.*epydoc\/uid.py:.*GtkDeprecationWarning', [
Stop('.*obj not in self._module.value', [
Block(None),
])
]),
Start('.* - twisted\.', [
Stop('.*\(base method=', [
Block(None),
])
]),
Start('.* - pb.BrokerFactory', [
Stop('.*\(from twisted.spread.flavors.Root.rootObject\)', [
Block(None),
])
]),
Start('.* - TestResult', [
Stop('.*\(from twisted.trial.unittest.TestCase.run\)', [
Block(None),
])
]),
]
singles = [
"^Warning: <type 'exceptions\.",
"^Warning: UID conflict detected: gobject",
"^Warning: UID conflict detected: __builtin__",
"^Warning: UID conflict detected: twisted",
".*- pb.getObjectAt \(from twisted.spread.flavors.Root\)",
".*- Deferred \(from twisted.trial.unittest.TestCase.run\)",
]
f = Filter(sys.stdin, sys.stdout)
for s in starts:
f.addStart(s)
for s in singles:
reo = re.compile(s)
f.addRegExpObject(reo)
f.start()
if __name__ == '__main__':
main()