(filename, byte_content=False, keep_newlines=False)
| 51 | |
| 52 | |
| 53 | def read_file(filename, byte_content=False, keep_newlines=False): |
| 54 | path = normalize_path(filename) |
| 55 | |
| 56 | mode = 'r' |
| 57 | if byte_content: |
| 58 | with open(path, mode + 'b') as f: |
| 59 | return f.read() |
| 60 | |
| 61 | try: |
| 62 | newline = '' if keep_newlines else None |
| 63 | with open(path, mode, newline=newline) as f: |
| 64 | return f.read() |
| 65 | |
| 66 | except UnicodeDecodeError as e: |
| 67 | encoded_result = try_encoded_read(path) |
| 68 | if encoded_result is not None: |
| 69 | return encoded_result |
| 70 | else: |
| 71 | raise e |
| 72 | |
| 73 | |
| 74 | def try_encoded_read(path): |
nothing calls this directly
no test coverage detected