summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorZachary Ware <zachary.ware@gmail.com>2013-11-26 20:55:46 (GMT)
committerZachary Ware <zachary.ware@gmail.com>2013-11-26 20:55:46 (GMT)
commit2a57009b04d01b7c2e72ee67f9ab4ce62c64167d (patch)
tree2f12f9127d5d8760bd54d578a1c46dbfce64f1d9 /Lib
parentc0aa2457d81ce65a80260472189812c7211f47fb (diff)
parent6d9d30da6a02a259c6d3df21c9e7f2aa5b3fd820 (diff)
downloadcpython-2a57009b04d01b7c2e72ee67f9ab4ce62c64167d.zip
cpython-2a57009b04d01b7c2e72ee67f9ab4ce62c64167d.tar.gz
cpython-2a57009b04d01b7c2e72ee67f9ab4ce62c64167d.tar.bz2
Merge heads
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_uuid.py20
-rw-r--r--Lib/uuid.py12
2 files changed, 30 insertions, 2 deletions
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
index 9de3d78..55b939f 100644
--- a/Lib/test/test_uuid.py
+++ b/Lib/test/test_uuid.py
@@ -1,5 +1,6 @@
import unittest
from test import test_support
+import io
import os
import uuid
@@ -346,6 +347,25 @@ class TestUUID(unittest.TestCase):
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.BytesIO(data)
+
+ with test_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
index cb4e5f0..4cd5194 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -307,8 +307,16 @@ def _find_mac(command, args, hw_identifiers, get_index):
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 IOError:
continue
return None