diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_uuid.py | 16 | ||||
-rw-r--r-- | Lib/uuid.py | 15 |
2 files changed, 23 insertions, 8 deletions
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py index 3842bb9..36266e1 100644 --- a/Lib/test/test_uuid.py +++ b/Lib/test/test_uuid.py @@ -284,7 +284,11 @@ class TestUUID(TestCase): msg = "different sources disagree on node:\n" for s, n in TestUUID.source2node.iteritems(): msg += " from source %r, node was %012x\n" % (s, n) - self.fail(msg) + # There's actually no reason to expect the MAC addresses + # to agree across various methods -- e.g., a box may have + # multiple network interfaces, and different ways of getting + # a MAC address may favor different HW. + ##self.fail(msg) else: TestUUID.last_node = node @@ -309,7 +313,7 @@ class TestUUID(TestCase): def test_random_getnode(self): node = uuid._random_getnode() self.assert_(0 <= node) - self.assert_(node < 1<<48L) + self.assert_(node < (1L <<48)) def test_unixdll_getnode(self): import os @@ -322,10 +326,14 @@ class TestUUID(TestCase): self.check_node(uuid._windll_getnode(), 'windll') def test_getnode(self): - self.check_node(uuid.getnode(), "getnode1") + node1 = uuid.getnode() + self.check_node(node1, "getnode1") # Test it again to ensure consistency. - self.check_node(uuid.getnode(), "getnode2") + node2 = uuid.getnode() + self.check_node(node2, "getnode2") + + self.assertEqual(node1, node2) def test_uuid1(self): equal = self.assertEqual diff --git a/Lib/uuid.py b/Lib/uuid.py index 11e0da3..dabe22e 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -362,6 +362,10 @@ try: # hardware address. On Windows 2000 and later, UuidCreate makes a # random UUID and UuidCreateSequential gives a UUID containing the # hardware address. These routines are provided by the RPC runtime. + # NOTE: at least on Tim's WinXP Pro SP2 desktop box, while the last + # 6 bytes returned by UuidCreateSequential are fixed, they don't appear + # to bear any relationship to the MAC address of any network device + # on the box. try: lib = ctypes.windll.rpcrt4 except: @@ -389,10 +393,13 @@ def _random_getnode(): _node = None def getnode(): - """Get the hardware address as a 48-bit integer. The first time this - runs, it may launch a separate program, which could be quite slow. If - all attempts to obtain the hardware address fail, we choose a random - 48-bit number with its eighth bit set to 1 as recommended in RFC 4122.""" + """Get the hardware address as a 48-bit positive integer. + + The first time this runs, it may launch a separate program, which could + be quite slow. If all attempts to obtain the hardware address fail, we + choose a random 48-bit number with its eighth bit set to 1 as recommended + in RFC 4122. + """ global _node if _node is not None: |