[Python-checkins] bpo-37364: Use io.open_code() to read .pth files (GH-14299)

Miss Islington (bot) webhook-mailer at python.org
Fri Jun 21 18:35:48 EDT 2019

commit: 35202c763703c9c00345b4445a638211e6e37bbc
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-06-21T15:35:44-07:00

bpo-37364: Use io.open_code() to read .pth files (GH-14299)

(cherry picked from commit 184f3d4f39056f6fe450d007d3b9b61d811a2a4d)

Co-authored-by: Steve Dower <steve.dower at python.org>

A Misc/NEWS.d/next/Security/2019-06-21-14-42-53.bpo-37364.IIRc2s.rst
M Lib/site.py

diff --git a/Lib/site.py b/Lib/site.py
index ad1146332b0a..e7aafb7011cf 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -73,6 +73,7 @@
 import os
 import builtins
 import _sitebuiltins
+import io
 # Prefixes for site-packages; add additional prefixes like /usr/local here
 PREFIXES = [sys.prefix, sys.exec_prefix]
@@ -156,7 +157,7 @@ def addpackage(sitedir, name, known_paths):
         reset = False
     fullname = os.path.join(sitedir, name)
-        f = open(fullname, "r")
+        f = io.TextIOWrapper(io.open_code(fullname))
     except OSError:
     with f:
diff --git a/Misc/NEWS.d/next/Security/2019-06-21-14-42-53.bpo-37364.IIRc2s.rst b/Misc/NEWS.d/next/Security/2019-06-21-14-42-53.bpo-37364.IIRc2s.rst
new file mode 100644
index 000000000000..7506fa9064b1
--- /dev/null
+++ b/Misc/NEWS.d/next/Security/2019-06-21-14-42-53.bpo-37364.IIRc2s.rst
@@ -0,0 +1 @@
+:func:`io.open_code` is now used when reading :file:`.pth` files.

More information about the Python-checkins mailing list