summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorZachary Ware <zachary.ware@gmail.com>2013-11-26 20:57:10 (GMT)
committerZachary Ware <zachary.ware@gmail.com>2013-11-26 20:57:10 (GMT)
commit99fb0513ddf8b0315ed717d08ced1fa28d144f05 (patch)
tree682abc19c49b58468f5168b70ddb120601eff164 /Lib
parenta6edea530bb9f3a9ff6234f443ea5d00428a7635 (diff)
parent56507c7862b6e2de189b6a942f394efb676cdb0b (diff)
downloadcpython-99fb0513ddf8b0315ed717d08ced1fa28d144f05.zip
cpython-99fb0513ddf8b0315ed717d08ced1fa28d144f05.tar.gz
cpython-99fb0513ddf8b0315ed717d08ced1fa28d144f05.tar.bz2
Merge heads
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_uuid.py21
-rw-r--r--Lib/uuid.py12
2 files changed, 31 insertions, 2 deletions
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
index 97ad6d0..0a47a91 100644
--- 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 @@ 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.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
index 9226fd4..d5c3160 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -327,8 +327,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