def __init__(self, handle, parser=None): """Initialize the iterator. Arguments: o handle - A handle with Saf entries to iterate through. o parser - An optional parser to pass the entries through before returning them. If None, then the raw entry will be returned. """ self.handle = File.UndoHandle(handle) self._reader = RecordReader.Everything(self.handle) self._parser = parser
def test_everything(): print "Testing Everything" s = "This is a test.\nThis is only a test.\nHad this been an actual...\n" for ending in ("\n", "\r", "\r\n"): data = string.replace(s, "\n", ending) for look in (0, 1, 2, 5): reader = RecordReader.Everything(StringIO(data[look:]), sizehint=1, lookahead=data[:look]) rec = reader.next() assert rec == data, "Record %r is not same as input %r" % \ (rec, data) infile, remainder = reader.remainder() remainder = remainder + infile.read() assert not remainder, "Why is there a remainder of %r?" % \ remainder rec = reader.next() assert rec is None, "Expecting None after final read, got %r" % \ rec rec = reader.next() assert rec is None, "Expecting None (again), got %r" % rec
def test_everything_lines(): lookahead = "1\n2\n3\n4\n5\n6\n7\n8\n" reader = RecordReader.Everything(StringIO(""), lookahead = lookahead) assert test_count(reader) == 1
def test_everything(): s = "1\n2\n3\n4\n5\n6\n7\n8\n" infile = StringIO(s) reader = RecordReader.Everything(infile) assert test_count(reader) == 1 assert not infile.readline()