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.
This commit is contained in:
Claude
2025-12-14 14:04:06 +00:00
parent 2a7d00d221
commit b830d15d85

View File

@@ -44,9 +44,13 @@ class Crypto:
try: try:
# Force English output for consistent parsing across locales # 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 import os
env = os.environ.copy() 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' env['LANG'] = 'C.UTF-8'
proc = subprocess.Popen( proc = subprocess.Popen(
@@ -56,7 +60,7 @@ class Crypto:
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True, text=True,
encoding='utf-8', encoding='utf-8',
errors='replace', # Replace invalid UTF-8 sequences instead of crashing errors='replace', # Handle encoding issues on any platform
env=env env=env
) )
stdout, stderr = proc.communicate(input=signed_content, timeout=10) stdout, stderr = proc.communicate(input=signed_content, timeout=10)