Skip to content

Commit 375c01b

Browse files
committed
fix: add explicit UTF-8 encoding to file operations in playwright_controller
1 parent b047730 commit 375c01b

8 files changed

Lines changed: 17 additions & 17 deletions

File tree

python/packages/autogen-ext/src/autogen_ext/code_executors/docker_jupyter/_docker_jupyter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def _save_html(self, html_data: str) -> str:
275275
"""Save html data to a file."""
276276
filename = f"{uuid.uuid4().hex}.html"
277277
path = os.path.join(str(self._output_dir), filename)
278-
with open(path, "w") as f:
278+
with open(path, "w", encoding="utf-8") as f:
279279
f.write(html_data)
280280
return os.path.abspath(path)
281281

python/packages/autogen-ext/src/autogen_ext/experimental/task_centric_memory/utils/chat_completion_client_recorder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(
7373
# Load the previously recorded messages and responses from disk.
7474
self.logger.info("Replay mode enabled.\nRetrieving session from: " + self.session_file_path)
7575
try:
76-
with open(self.session_file_path, "r") as f:
76+
with open(self.session_file_path, "r", encoding="utf-8") as f:
7777
self.records = json.load(f)
7878
except Exception as e:
7979
error_str = f"\nFailed to load recorded session: '{self.session_file_path}': {e}"
@@ -211,7 +211,7 @@ def finalize(self) -> None:
211211
# Create the directory if it doesn't exist.
212212
os.makedirs(os.path.dirname(self.session_file_path), exist_ok=True)
213213
# Write the records to disk.
214-
with open(self.session_file_path, "w") as f:
214+
with open(self.session_file_path, "w", encoding="utf-8") as f:
215215
json.dump(self.records, f, indent=2)
216216
self.logger.info("\nRecorded session was saved to: " + self.session_file_path)
217217
except Exception as e:

python/packages/autogen-ext/src/autogen_ext/experimental/task_centric_memory/utils/page_logger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def finalize(self) -> None:
117117
# Write the hash and other details to a file.
118118
hash_str, num_files, num_subdirs = hash_directory(self.log_dir)
119119
hash_path = os.path.join(self.log_dir, "hash.txt")
120-
with open(hash_path, "w") as f:
120+
with open(hash_path, "w", encoding="utf-8") as f:
121121
f.write(hash_str)
122122
f.write("\n")
123123
f.write("{} files\n".format(num_files))
@@ -386,7 +386,7 @@ def flush(self, finished: bool = False) -> None:
386386
return
387387
# Create a call tree of the log.
388388
call_tree_path = os.path.join(self.log_dir, self.name + ".html")
389-
with open(call_tree_path, "w") as f:
389+
with open(call_tree_path, "w", encoding="utf-8") as f:
390390
f.write(_html_opening("0 Call Tree", finished=finished))
391391
f.write(f"<h3>{self.name}</h3>")
392392
f.write("\n")
@@ -498,7 +498,7 @@ def flush(self) -> None:
498498
Writes the HTML page to disk.
499499
"""
500500
page_path = os.path.join(self.page_logger.log_dir, self.index_str + ".html")
501-
with open(page_path, "w") as f:
501+
with open(page_path, "w", encoding="utf-8") as f:
502502
f.write(_html_opening(self.file_title, finished=self.finished))
503503
f.write(f"<h3>{self.file_title}</h3>\n")
504504
for line in self.lines:

python/packages/autogen-studio/autogenstudio/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def ui(
6969

7070
# Create temporary env file to share configuration with uvicorn workers
7171
env_file_path = get_env_file_path()
72-
with open(env_file_path, "w") as temp_env:
72+
with open(env_file_path, "w", encoding="utf-8") as temp_env:
7373
for key, value in env_vars.items():
7474
temp_env.write(f"{key}={value}\n")
7575

python/packages/autogen-studio/autogenstudio/database/schema_manager.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _update_configuration(self) -> None:
7575

7676
# Update alembic.ini
7777
config_content = self._generate_alembic_ini_content()
78-
with open(self.alembic_ini_path, "w") as f:
78+
with open(self.alembic_ini_path, "w", encoding="utf-8") as f:
7979
f.write(config_content)
8080

8181
# Update env.py
@@ -115,7 +115,7 @@ def _initialize_alembic(self) -> bool:
115115

116116
# Create initial config file for alembic init
117117
config_content = self._generate_alembic_ini_content()
118-
with open(self.alembic_ini_path, "w") as f:
118+
with open(self.alembic_ini_path, "w", encoding="utf-8") as f:
119119
f.write(config_content)
120120

121121
# Use the config we just created
@@ -187,7 +187,7 @@ def run_migrations_online() -> None:
187187
else:
188188
run_migrations_online()"""
189189

190-
with open(env_path, "w") as f:
190+
with open(env_path, "w", encoding="utf-8") as f:
191191
f.write(content)
192192

193193
def _generate_alembic_ini_content(self) -> str:
@@ -239,7 +239,7 @@ def update_script_template(self):
239239
"""Update the Alembic script template to include SQLModel."""
240240
template_path = self.alembic_dir / "script.py.mako"
241241
try:
242-
with open(template_path, "r") as f:
242+
with open(template_path, "r", encoding="utf-8") as f:
243243
content = f.read()
244244

245245
# Add sqlmodel import to imports section
@@ -248,7 +248,7 @@ def update_script_template(self):
248248

249249
content = content.replace(import_section, new_imports)
250250

251-
with open(template_path, "w") as f:
251+
with open(template_path, "w", encoding="utf-8") as f:
252252
f.write(content)
253253

254254
return True
@@ -265,7 +265,7 @@ def _update_env_py(self, env_path: Path) -> None:
265265
self._create_minimal_env_py(env_path)
266266
return
267267
try:
268-
with open(env_path, "r") as f:
268+
with open(env_path, "r", encoding="utf-8") as f:
269269
content = f.read()
270270

271271
# Add SQLModel import if not present
@@ -303,7 +303,7 @@ def _update_env_py(self, env_path: Path) -> None:
303303
)""",
304304
)
305305

306-
with open(env_path, "w") as f:
306+
with open(env_path, "w", encoding="utf-8") as f:
307307
f.write(content)
308308
except Exception as e:
309309
logger.error(f"Failed to update env.py: {e}")

python/packages/autogen-studio/autogenstudio/gallery/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,5 +630,5 @@ def create_default_lite_team():
630630
gallery = create_default_gallery()
631631

632632
# Save to file
633-
with open("gallery_default.json", "w") as f:
633+
with open("gallery_default.json", "w", encoding="utf-8") as f:
634634
f.write(gallery.model_dump_json(indent=2))

python/packages/autogen-studio/autogenstudio/lite/studio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _setup_environment(self) -> str:
151151
}
152152

153153
env_file_path = self._get_env_file_path()
154-
with open(env_file_path, "w") as temp_env:
154+
with open(env_file_path, "w", encoding="utf-8") as temp_env:
155155
for key, value in env_vars.items():
156156
temp_env.write(f"{key}={value}\n")
157157

python/packages/autogen-studio/autogenstudio/web/auth/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def is_valid_token(self, token: str) -> bool:
117117
def from_yaml(cls, yaml_path: str) -> Self:
118118
"""Create AuthManager from YAML config file."""
119119
try:
120-
with open(yaml_path, "r") as f:
120+
with open(yaml_path, "r", encoding="utf-8") as f:
121121
config_data = yaml.safe_load(f)
122122
config = AuthConfig(**config_data)
123123
return cls(config)

0 commit comments

Comments
 (0)