paul@277 | 1 | #!/usr/bin/env python |
paul@277 | 2 | |
paul@277 | 3 | """ |
paul@277 | 4 | File utilities. |
paul@277 | 5 | |
paul@300 | 6 | Copyright (C) 2019, 2021 Paul Boddie <paul@boddie.org.uk> |
paul@277 | 7 | |
paul@277 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@277 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@277 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@277 | 11 | version. |
paul@277 | 12 | |
paul@277 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@277 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@277 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@277 | 16 | details. |
paul@277 | 17 | |
paul@277 | 18 | You should have received a copy of the GNU General Public License along with |
paul@277 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@277 | 20 | """ |
paul@277 | 21 | |
paul@277 | 22 | import codecs |
paul@277 | 23 | |
paul@277 | 24 | def readfile(filename, encoding): |
paul@277 | 25 | |
paul@277 | 26 | """ |
paul@277 | 27 | Return the contents of the file having the given 'filename' and employing |
paul@277 | 28 | the given 'encoding'. |
paul@277 | 29 | """ |
paul@277 | 30 | |
paul@277 | 31 | f = codecs.open(filename, encoding=encoding) |
paul@277 | 32 | try: |
paul@300 | 33 | return f.read().replace("\r\n", "\n") |
paul@277 | 34 | finally: |
paul@277 | 35 | f.close() |
paul@277 | 36 | |
paul@277 | 37 | # vim: tabstop=4 expandtab shiftwidth=4 |