paul@6 | 1 | #!/usr/bin/env python |
paul@6 | 2 | |
paul@6 | 3 | """ |
paul@11 | 4 | Reader classes for indexing. |
paul@6 | 5 | |
paul@6 | 6 | Copyright (C) 2011 Paul Boddie <paul@boddie.org.uk> |
paul@6 | 7 | |
paul@6 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@6 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@6 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@6 | 11 | version. |
paul@6 | 12 | |
paul@6 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT ANY |
paul@6 | 14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
paul@6 | 15 | PARTICULAR PURPOSE. See the GNU General Public License for more details. |
paul@6 | 16 | |
paul@6 | 17 | You should have received a copy of the GNU General Public License along |
paul@6 | 18 | with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@6 | 19 | """ |
paul@6 | 20 | |
paul@10 | 21 | class File: |
paul@6 | 22 | |
paul@10 | 23 | "A generic file wrapper." |
paul@6 | 24 | |
paul@11 | 25 | def __init__(self, f, iterator): |
paul@6 | 26 | self.f = f |
paul@11 | 27 | self.iterator = iterator |
paul@6 | 28 | |
paul@6 | 29 | def seek(self, pos): |
paul@6 | 30 | self.f.seek(pos) |
paul@6 | 31 | |
paul@10 | 32 | class TextFile(File): |
paul@10 | 33 | |
paul@10 | 34 | "A wrapper around text files." |
paul@10 | 35 | |
paul@8 | 36 | def __iter__(self): |
paul@11 | 37 | self.iterator.set_records(self.f.xreadlines()) |
paul@11 | 38 | return self.iterator |
paul@9 | 39 | |
paul@6 | 40 | # vim: tabstop=4 expandtab shiftwidth=4 |