summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-12-04 09:51:55 (GMT)
committerGitHub <noreply@github.com>2017-12-04 09:51:55 (GMT)
commite69fbb6a560a02d0587b9075afd338a1e9073af0 (patch)
treeebd63b48c91ad576730b0cd1dcbeb070f37ea28d /Lib
parent85d5c18c9d83a1d54eecc4c2ad4dce63194107c6 (diff)
downloadcpython-e69fbb6a560a02d0587b9075afd338a1e9073af0.zip
cpython-e69fbb6a560a02d0587b9075afd338a1e9073af0.tar.gz
cpython-e69fbb6a560a02d0587b9075afd338a1e9073af0.tar.bz2
Fix a regression in uuid added in bpo-32107. (#4677)
uuid.get_node() always must return a stable result. Also added a test for non-reproducibility of _random_getnode(). Original patch by Xavier de Gaye.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_uuid.py3
-rw-r--r--Lib/uuid.py4
2 files changed, 5 insertions, 2 deletions
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
index f113c55..f21bd6d 100644
--- a/Lib/test/test_uuid.py
+++ b/Lib/test/test_uuid.py
@@ -565,6 +565,9 @@ eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
self.assertTrue(node & (1 << 40), '%012x' % node)
self.check_node(node)
+ node2 = self.uuid._random_getnode()
+ self.assertNotEqual(node2, node, '%012x' % node)
+
@unittest.skipUnless(os.name == 'posix', 'requires Posix')
def test_unix_getnode(self):
if not importable('_uuid') and not importable('ctypes'):
diff --git a/Lib/uuid.py b/Lib/uuid.py
index cb2bc09..be06a6e 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -674,14 +674,14 @@ def getnode():
getters = [_unix_getnode, _ifconfig_getnode, _ip_getnode,
_arp_getnode, _lanscan_getnode, _netstat_getnode]
- for getter in getters:
+ for getter in getters + [_random_getnode]:
try:
_node = getter()
except:
continue
if _node is not None:
return _node
- return _random_getnode()
+ assert False, '_random_getnode() returned None'
_last_timestamp = None