Revision 1706
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/streams.py | ||
---|---|---|
69 | 69 |
|
70 | 70 |
class CaptureStream(TracedStream): |
71 | 71 |
'''Wraps a stream, capturing matching text. |
72 |
Matched text can be retrieved from self.match.'''
|
|
72 |
Matches can be retrieved from self.matches.'''
|
|
73 | 73 |
def __init__(self, stream, start_str, end_str): |
74 | 74 |
self.recording = False |
75 |
self.match = ''
|
|
75 |
self.matches = []
|
|
76 | 76 |
|
77 | 77 |
def trace(str_): |
78 | 78 |
start_idx = str_.find(start_str) |
79 |
if start_idx >= 0: self.recording = True |
|
79 |
if start_idx >= 0: |
|
80 |
self.recording = True |
|
81 |
self.matches.append('') |
|
80 | 82 |
else: start_idx = 0 |
81 | 83 |
|
82 | 84 |
recording = self.recording # save recording status |
... | ... | |
87 | 89 |
end_idx += len(end_str) |
88 | 90 |
else: end_idx = len(str_) |
89 | 91 |
|
90 |
if recording: self.match += str_[start_idx:end_idx] |
|
92 |
if recording: self.matches[-1] += str_[start_idx:end_idx]
|
|
91 | 93 |
|
92 | 94 |
TracedStream.__init__(self, trace, stream) |
bin/digir_client | ||
---|---|---|
135 | 135 |
stream.close() |
136 | 136 |
|
137 | 137 |
# Parse diagnostics |
138 |
diags_str = stream.match |
|
138 |
diags_str = stream.matches[0]
|
|
139 | 139 |
debug_log(diags_str, 'diagnostics') |
140 | 140 |
diags = xml_dom.parse_str(diags_str) |
141 | 141 |
def get_diag(name): |
Also available in: Unified diff
streams.py: CaptureStream: Get each match as a separate array elem instead of concatenated together