Index: trunk/tools/wsor/scripts/classes/file_wrapper.py |
— | — | @@ -1,6 +1,30 @@ |
2 | 2 | import sys |
3 | 3 | from StringIO import StringIO |
| 4 | +from collections import deque |
4 | 5 | |
| 6 | +class RecordingFileWrapper(FileWrapper): |
| 7 | + |
| 8 | + def __init__(self, fp, pre='', post='', record=10000): |
| 9 | + self.history = deque(maxsize=record) |
| 10 | + FileWrapper.__init__(self, fp, pre=pre, post=post) |
| 11 | + |
| 12 | + def read(self, bytes=sys.maxint): |
| 13 | + outBytes = FileWrapper.read(self, bytes) |
| 14 | + self.history.extend(outBytes) |
| 15 | + return outBytes |
| 16 | + |
| 17 | + def readline(self): |
| 18 | + outBytes = FileWrapper.readline(self) |
| 19 | + self.history.extend(outBytes) |
| 20 | + return outBytes |
| 21 | + |
| 22 | + def getHistory(self): |
| 23 | + return ''.join(self.history) |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
5 | 29 | class FileWrapper: |
6 | 30 | |
7 | 31 | def __init__(self, fp, pre='', post=''): |