From 7e3609f19fb29412d57e2556af77ebc2f968e02d Mon Sep 17 00:00:00 2001 From: Sheng Fan Date: Wed, 19 Mar 2025 14:10:07 +0800 Subject: [PATCH] chore(file_operators): use utf-8 as default encoding --- app/tool/file_operators.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/tool/file_operators.py b/app/tool/file_operators.py index 61f8b16..5720172 100644 --- a/app/tool/file_operators.py +++ b/app/tool/file_operators.py @@ -42,17 +42,20 @@ class FileOperator(Protocol): class LocalFileOperator(FileOperator): """File operations implementation for local filesystem.""" + def __init__(self, encoding: str = "utf-8"): + self.encoding = encoding + async def read_file(self, path: PathLike) -> str: """Read content from a local file.""" try: - return Path(path).read_text() + return Path(path).read_text(encoding=self.encoding) except Exception as e: raise ToolError(f"Failed to read {path}: {str(e)}") from None async def write_file(self, path: PathLike, content: str) -> None: """Write content to a local file.""" try: - Path(path).write_text(content) + Path(path).write_text(content, encoding=self.encoding) except Exception as e: raise ToolError(f"Failed to write to {path}: {str(e)}") from None