Reads the file at the given path and returns the contents as a string.
(logger: MultilspyLogger, file_path: str)
| 91 | |
| 92 | @staticmethod |
| 93 | def read_file(logger: MultilspyLogger, file_path: str) -> str: |
| 94 | """ |
| 95 | Reads the file at the given path and returns the contents as a string. |
| 96 | """ |
| 97 | encodings = ["utf-8-sig", "utf-16"] |
| 98 | try: |
| 99 | for encoding in encodings: |
| 100 | try: |
| 101 | with open(file_path, "r", encoding=encoding) as inp_file: |
| 102 | return inp_file.read() |
| 103 | except UnicodeError: |
| 104 | continue |
| 105 | except Exception as exc: |
| 106 | logger.log(f"File read '{file_path}' failed: {exc}", logging.ERROR) |
| 107 | raise MultilspyException("File read failed.") from None |
| 108 | logger.log(f"File read '{file_path}' failed: Unsupported encoding.", logging.ERROR) |
| 109 | raise MultilspyException(f"File read '{file_path}' failed: Unsupported encoding.") from None |
| 110 | |
| 111 | @staticmethod |
| 112 | def download_file(logger: MultilspyLogger, url: str, target_path: str) -> None: |
no test coverage detected