Reads the file at the given path and returns the contents as a string.
(logger: MultilspyLogger, file_path: str)
| 103 | |
| 104 | @staticmethod |
| 105 | def read_file(logger: MultilspyLogger, file_path: str) -> str: |
| 106 | """ |
| 107 | Reads the file at the given path and returns the contents as a string. |
| 108 | """ |
| 109 | encodings = ["utf-8-sig", "utf-16"] |
| 110 | try: |
| 111 | for encoding in encodings: |
| 112 | try: |
| 113 | with open(file_path, "r", encoding=encoding) as inp_file: |
| 114 | return inp_file.read() |
| 115 | except UnicodeError: |
| 116 | continue |
| 117 | except Exception as exc: |
| 118 | logger.log(f"File read '{file_path}' failed: {exc}", logging.ERROR) |
| 119 | raise MultilspyException("File read failed.") from None |
| 120 | logger.log( |
| 121 | f"File read '{file_path}' failed: Unsupported encoding.", logging.ERROR |
| 122 | ) |
| 123 | raise MultilspyException( |
| 124 | f"File read '{file_path}' failed: Unsupported encoding." |
| 125 | ) from None |
| 126 | |
| 127 | @staticmethod |
| 128 | def download_file(logger: MultilspyLogger, url: str, target_path: str) -> None: |
no test coverage detected