Skip to content

Commit 88ed2cb

Browse files
bundoleeclaude
andcommitted
fix(runner): remove dead locale import and harden encoding robustness
- Remove unused `import locale` (dead after encoding fix, fails ruff F401) - Add `errors="replace"` to both subprocess calls for resilience against unexpected non-UTF-8 bytes in JVM error output - Guard `sys.stdout.buffer` access with hasattr for redirected-stdout environments (test fixtures, io.StringIO, etc.) - Add `sys.stdout.buffer.flush()` to ensure real-time streaming output Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent eaa42e3 commit 88ed2cb

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • python/opendataloader-pdf/src/opendataloader_pdf

python/opendataloader-pdf/src/opendataloader_pdf/runner.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Low-level JAR runner for opendataloader-pdf.
33
"""
4-
import locale
54
import subprocess
65
import sys
76
import importlib.resources as resources
@@ -27,6 +26,7 @@ def run_jar(args: List[str], quiet: bool = False) -> str:
2726
text=True,
2827
check=True,
2928
encoding="utf-8",
29+
errors="replace",
3030
)
3131
return result.stdout
3232

@@ -37,10 +37,15 @@ def run_jar(args: List[str], quiet: bool = False) -> str:
3737
stderr=subprocess.STDOUT,
3838
text=True,
3939
encoding="utf-8",
40+
errors="replace",
4041
) as process:
4142
output_lines: List[str] = []
4243
for line in process.stdout:
43-
sys.stdout.buffer.write(line.encode("utf-8", errors="replace"))
44+
if hasattr(sys.stdout, "buffer"):
45+
sys.stdout.buffer.write(line.encode("utf-8", errors="replace"))
46+
sys.stdout.buffer.flush()
47+
else:
48+
sys.stdout.write(line)
4449
output_lines.append(line)
4550

4651
return_code = process.wait()

0 commit comments

Comments
 (0)