[3.6] bpo-32370: Use the correct encoding for ipconfig output in the uuid module. (GH-5608). (#5654)

(cherry picked from commit da6c3da6c3)


Co-authored-by: Segev Finer <segev208@gmail.com>
This commit is contained in:
Serhiy Storchaka 2018-02-13 11:15:21 +02:00 committed by GitHub
parent 9fad857444
commit c3f9d7e0ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -419,7 +419,7 @@ def _netstat_getnode():
def _ipconfig_getnode():
"""Get the hardware address on Windows by running ipconfig.exe."""
import os, re
import os, re, subprocess
dirs = ['', r'c:\windows\system32', r'c:\winnt\system32']
try:
import ctypes
@ -430,11 +430,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):
return int(value.replace('-', ''), 16)

View File

@ -0,0 +1,2 @@
Use the correct encoding for ipconfig output in the uuid module.
Patch by Segev Finer.