Return the file for a given filename. If you want binary content use ``mode='rb'``.
(self, filename, binary=False)
| 71 | |
| 72 | """ |
| 73 | def file_contents(self, filename, binary=False): |
| 74 | """Return the file for a given filename. |
| 75 | |
| 76 | If you want binary content use ``mode='rb'``. |
| 77 | |
| 78 | """ |
| 79 | if binary: |
| 80 | mode = 'rb' |
| 81 | else: |
| 82 | mode = 'r' |
| 83 | try: |
| 84 | with open(filename, mode) as f: |
| 85 | return f.read() |
| 86 | except (OSError, IOError) as e: |
| 87 | raise FileReadError(str(e)) |
| 88 | |
| 89 | def file_exists(self, filename): |
| 90 | """Check if a file exists. |