From d0375e712ecbc2b1dbb410f47bc6ca573c44f703 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Sat, 10 Feb 2018 15:38:56 +0200 Subject: [PATCH 1/2] bpo-32370: Use the correct encoding for ipconfig output in the uuid module --- Lib/uuid.py | 10 ++++++---- .../Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst diff --git a/Lib/uuid.py b/Lib/uuid.py index ef7b3b59241f4b4..9cb73e87718122c 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -468,7 +468,7 @@ def _netstat_getnode(): def _ipconfig_getnode(): """Get the hardware address on Windows by running ipconfig.exe.""" - import os, re + import os, re, subprocess first_local_mac = None dirs = ['', r'c:\windows\system32', r'c:\winnt\system32'] try: @@ -480,11 +480,13 @@ def _ipconfig_getnode(): pass for dir in dirs: try: - pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all') + proc = subprocess.Popen([os.path.join(dir, 'ipconfig'), '/all'], + stdout=subprocess.PIPE, + encoding="oem") except OSError: continue - with pipe: - for line in pipe: + with proc: + for line in proc.stdout: value = line.split(':')[-1].strip().lower() if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value): mac = int(value.replace('-', ''), 16) diff --git a/Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst b/Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst new file mode 100644 index 000000000000000..d9ac0d8440e849a --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst @@ -0,0 +1 @@ +Use the correct encoding for ipconfig output in the uuid module. From 6f52352ea35fa9ca24a38be3573c1c34f067ce47 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 11 Feb 2018 12:47:33 +0200 Subject: [PATCH 2/2] Add credits. --- .../NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst b/Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst index d9ac0d8440e849a..7f076d45bef9dbb 100644 --- a/Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst +++ b/Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst @@ -1 +1,2 @@ Use the correct encoding for ipconfig output in the uuid module. +Patch by Segev Finer.