From b830d15d8500cf22ce8a9a4cac36db6583555e78 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 14 Dec 2025 14:04:06 +0000 Subject: [PATCH] Add cross-platform compatibility documentation for GPG locale handling Clarified how the locale override works across different platforms: - Linux/macOS: LC_ALL and LANG variables control GPG output language - Windows: GPG may ignore locale variables, but the code remains robust through explicit encoding='utf-8' and errors='replace' parameters The combination of: 1. Setting LC_ALL/LANG to C.UTF-8 (works on Linux/macOS) 2. Explicit encoding='utf-8' parameter 3. errors='replace' for graceful handling ...ensures the code works reliably on all platforms even if the locale setting is not fully respected by GPG. --- trace/crypto.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/trace/crypto.py b/trace/crypto.py index 8b4eaa4..18f723e 100644 --- a/trace/crypto.py +++ b/trace/crypto.py @@ -44,9 +44,13 @@ class Crypto: try: # Force English output for consistent parsing across locales + # Linux/macOS: LC_ALL/LANG variables control GPG's output language + # Windows: GPG may ignore these, but encoding='utf-8' + errors='replace' provides robustness import os env = os.environ.copy() - env['LC_ALL'] = 'C.UTF-8' # Use UTF-8 variant to handle international characters + # Use C.UTF-8 for English messages with UTF-8 encoding support + # Falls back gracefully via errors='replace' if locale not available + env['LC_ALL'] = 'C.UTF-8' env['LANG'] = 'C.UTF-8' proc = subprocess.Popen( @@ -56,7 +60,7 @@ class Crypto: stderr=subprocess.PIPE, text=True, encoding='utf-8', - errors='replace', # Replace invalid UTF-8 sequences instead of crashing + errors='replace', # Handle encoding issues on any platform env=env ) stdout, stderr = proc.communicate(input=signed_content, timeout=10)