From 77a45b0e3a7ddabbf3500d7f22a13bfb157b291e Mon Sep 17 00:00:00 2001 From: Alyssa Coghlan Date: Fri, 24 May 2024 22:21:42 +1000 Subject: [PATCH 1/3] Accept UTF-8 BOM in .pth files `Out-File -Encoding utf8` in Windows Powershell 5.1 emits UTF-8 with a BOM maker, which the regular `utf-8` codec decodes incorrectly. `utf-8-sig` accepts a BOM, but also works correctly without one. --- Lib/site.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/site.py b/Lib/site.py index f1a6d9cf66fdc3..b073cdbd46819e 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -185,7 +185,9 @@ def addpackage(sitedir, name, known_paths): return try: - pth_content = pth_content.decode() + # Accept BOM markers in .pth files as we do in source files + # (Windows PowerShell 5.1 makes it hard to emit UTF-8 files without a BOM) + pth_content = pth_content.decode(encoding="utf8-sig") except UnicodeDecodeError: # Fallback to locale encoding for backward compatibility. # We will deprecate this fallback in the future. From 1c2b313f884406335e350a2d89c3add702c8f675 Mon Sep 17 00:00:00 2001 From: Alyssa Coghlan Date: Fri, 24 May 2024 22:23:25 +1000 Subject: [PATCH 2/3] Update site.py --- Lib/site.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/site.py b/Lib/site.py index b073cdbd46819e..c702ff38e8df23 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -187,7 +187,7 @@ def addpackage(sitedir, name, known_paths): try: # Accept BOM markers in .pth files as we do in source files # (Windows PowerShell 5.1 makes it hard to emit UTF-8 files without a BOM) - pth_content = pth_content.decode(encoding="utf8-sig") + pth_content = pth_content.decode(encoding="utf-8-sig") except UnicodeDecodeError: # Fallback to locale encoding for backward compatibility. # We will deprecate this fallback in the future. From 1828c45d03486eca8b962ad5e630bbf251b8238c Mon Sep 17 00:00:00 2001 From: Alyssa Coghlan Date: Sat, 25 May 2024 00:05:45 +1000 Subject: [PATCH 3/3] Simpliy decode call Co-authored-by: Inada Naoki --- Lib/site.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/site.py b/Lib/site.py index c702ff38e8df23..7eace190f5ab21 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -187,7 +187,7 @@ def addpackage(sitedir, name, known_paths): try: # Accept BOM markers in .pth files as we do in source files # (Windows PowerShell 5.1 makes it hard to emit UTF-8 files without a BOM) - pth_content = pth_content.decode(encoding="utf-8-sig") + pth_content = pth_content.decode("utf-8-sig") except UnicodeDecodeError: # Fallback to locale encoding for backward compatibility. # We will deprecate this fallback in the future.