MCPcopy Create free account
hub / github.com/FSoft-AI4Code/HyperAgent / read_file

Method read_file

src/hyperagent/multilspy/multilspy_utils.py:93–109  ·  view source on GitHub ↗

Reads the file at the given path and returns the contents as a string.

(logger: MultilspyLogger, file_path: str)

Source from the content-addressed store, hash-verified

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:

Callers 1

open_fileMethod · 0.80

Calls 2

MultilspyExceptionClass · 0.90
logMethod · 0.80

Tested by

no test coverage detected