paul@104 | 1 | #!/usr/bin/env python |
paul@104 | 2 | |
paul@104 | 3 | """ |
paul@104 | 4 | Directory input context. |
paul@104 | 5 | |
paul@104 | 6 | Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> |
paul@104 | 7 | |
paul@104 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@104 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@104 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@104 | 11 | version. |
paul@104 | 12 | |
paul@104 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@104 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@104 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@104 | 16 | details. |
paul@104 | 17 | |
paul@104 | 18 | You should have received a copy of the GNU General Public License along with |
paul@104 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@104 | 20 | """ |
paul@104 | 21 | |
paul@104 | 22 | from moinformat.input.common import Input |
paul@104 | 23 | from moinformat.utils.directory import Directory |
paul@104 | 24 | |
paul@104 | 25 | class DirectoryInput(Input, Directory): |
paul@104 | 26 | |
paul@104 | 27 | "A directory output context." |
paul@104 | 28 | |
paul@104 | 29 | name = "directory" |
paul@104 | 30 | |
paul@104 | 31 | def __init__(self, parameters=None): |
paul@104 | 32 | |
paul@104 | 33 | "Initialise the context with the given 'parameters'." |
paul@104 | 34 | |
paul@104 | 35 | if not parameters or not parameters.has_key("filename"): |
paul@104 | 36 | raise ValueError, parameters |
paul@104 | 37 | |
paul@104 | 38 | Input.__init__(self, parameters) |
paul@104 | 39 | Directory.__init__(self, parameters["filename"]) |
paul@104 | 40 | |
paul@104 | 41 | def readfile(self, filename, encoding=None): |
paul@104 | 42 | |
paul@104 | 43 | """ |
paul@104 | 44 | Return the contents of the file having the given 'filename' and optional |
paul@104 | 45 | 'encoding'. |
paul@104 | 46 | """ |
paul@104 | 47 | |
paul@104 | 48 | return Input.readfile(self, self.get_filename(filename), encoding) |
paul@104 | 49 | |
paul@104 | 50 | input = DirectoryInput |
paul@104 | 51 | |
paul@104 | 52 | # vim: tabstop=4 expandtab shiftwidth=4 |