[Python-checkins] cpython (merge 3.3 -> default): Issue #11508: Fixed uuid.getnode() and uuid.uuid1() on environment with
serhiy.storchaka
python-checkins at python.org
Tue Nov 26 21:50:06 CET 2013
http://hg.python.org/cpython/rev/efd0e6d675ff
changeset: 87595:efd0e6d675ff
parent: 87592:08bcbc210a0f
parent: 87594:a5c26e57f429
user: Serhiy Storchaka <storchaka at gmail.com>
date: Tue Nov 26 22:49:36 2013 +0200
summary:
Issue #11508: Fixed uuid.getnode() and uuid.uuid1() on environment with
virtual interface. Original patch by Kent Frazier.
files:
Lib/test/test_uuid.py | 21 +++++++++++++++++++++
Lib/uuid.py | 12 ++++++++++--
Misc/ACKS | 1 +
Misc/NEWS | 3 +++
4 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
--- a/Lib/test/test_uuid.py
+++ b/Lib/test/test_uuid.py
@@ -1,5 +1,7 @@
import unittest
+from test import support
import builtins
+import io
import os
import uuid
@@ -356,6 +358,25 @@
self.assertEqual(node1, node2)
+ def test_find_mac(self):
+ data = '''\
+
+fake hwaddr
+cscotun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
+eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
+'''
+ def mock_popen(cmd):
+ return io.StringIO(data)
+
+ with support.swap_attr(os, 'popen', mock_popen):
+ mac = uuid._find_mac(
+ command='ifconfig',
+ args='',
+ hw_identifiers=['hwaddr'],
+ get_index=lambda x: x + 1,
+ )
+ self.assertEqual(mac, 0x1234567890ab)
+
@unittest.skipUnless(importable('ctypes'), 'requires ctypes')
def test_uuid1(self):
equal = self.assertEqual
diff --git a/Lib/uuid.py b/Lib/uuid.py
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -327,8 +327,16 @@
words = line.lower().split()
for i in range(len(words)):
if words[i] in hw_identifiers:
- return int(
- words[get_index(i)].replace(':', ''), 16)
+ try:
+ return int(
+ words[get_index(i)].replace(':', ''), 16)
+ except (ValueError, IndexError):
+ # Virtual interfaces, such as those provided by
+ # VPNs, do not have a colon-delimited MAC address
+ # as expected, but a 16-byte HWAddr separated by
+ # dashes. These should be ignored in favor of a
+ # real MAC address
+ pass
except OSError:
continue
return None
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -407,6 +407,7 @@
Andrew Francis
Stefan Franke
Martin Franklin
+Kent Frazier
Bruce Frederiksen
Robin Friedrich
Bradley Froehle
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,9 @@
Library
-------
+- Issue #11508: Fixed uuid.getnode() and uuid.uuid1() on environment with
+ virtual interface. Original patch by Kent Frazier.
+
- Issue #11489: JSON decoder now accepts lone surrogates.
- Issue #19545: Avoid chained exceptions while passing stray % to
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list