Get the contents of a file. Args: filename: str with the file to be read mode: "r" for str, "rb" for bytes result encoding: optional encoding to used when reading the file, e.g. "utf8" errors: optional error handler decoding the content, as defined in `codecs`
(filename, mode="r", encoding=None, errors=None)
| 1122 | |
| 1123 | |
| 1124 | def getFileContents(filename, mode="r", encoding=None, errors=None): |
| 1125 | """Get the contents of a file. |
| 1126 | |
| 1127 | Args: |
| 1128 | filename: str with the file to be read |
| 1129 | mode: "r" for str, "rb" for bytes result |
| 1130 | encoding: optional encoding to used when reading the file, e.g. "utf8" |
| 1131 | errors: optional error handler decoding the content, as defined in `codecs` |
| 1132 | |
| 1133 | Returns: |
| 1134 | str or bytes - depending on mode. |
| 1135 | |
| 1136 | """ |
| 1137 | |
| 1138 | with withFileLock("reading file %s" % filename): |
| 1139 | with openTextFile(filename, mode, encoding=encoding, errors=errors) as f: |
| 1140 | return f.read() |
| 1141 | |
| 1142 | |
| 1143 | def stripFileContentsBOM(contents): |
no test coverage detected
searching dependent graphs…