]> granicus.if.org Git - python/commitdiff
bpo-32370: Use the correct encoding for ipconfig output in the uuid module. (GH-5608)
authorSegev Finer <segev208@gmail.com>
Tue, 13 Feb 2018 06:29:54 +0000 (08:29 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 13 Feb 2018 06:29:54 +0000 (08:29 +0200)
Lib/uuid.py
Misc/NEWS.d/next/Windows/2018-02-10-15-38-19.bpo-32370.kcKuct.rst [new file with mode: 0644]

index ef7b3b59241f4b4069e215a993d6574defae9aea..9cb73e87718122c3a4cd7ee38d1e21e2de996177 100644 (file)
@@ -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 (file)
index 0000000..7f076d4
--- /dev/null
@@ -0,0 +1,2 @@
+Use the correct encoding for ipconfig output in the uuid module.
+Patch by Segev Finer.