Live with that "the hardware address" is an ill-defined
concept, and that different ways of trying to find "the hardware address" may return different results. Certainly true on both of my Windows boxes, and in different ways (see whining on python-dev).
This commit is contained in:
parent
df80af7659
commit
750c4420a8
|
@ -32,7 +32,7 @@ fields\optional{, int\optional{, version}}}}}}
|
||||||
|
|
||||||
Create a UUID from either a string of 32 hexadecimal digits,
|
Create a UUID from either a string of 32 hexadecimal digits,
|
||||||
a string of 16 bytes as the \var{bytes} argument, a tuple of six
|
a string of 16 bytes as the \var{bytes} argument, a tuple of six
|
||||||
integers (32-bit \var{time_low}, 16-bit \var{time_mid},
|
integers (32-bit \var{time_low}, 16-bit \var{time_mid},
|
||||||
16-bit \var{time_hi_version},
|
16-bit \var{time_hi_version},
|
||||||
8-bit \var{clock_seq_hi_variant}, 8-bit \var{clock_seq_low}, 48-bit \var{node})
|
8-bit \var{clock_seq_hi_variant}, 8-bit \var{clock_seq_low}, 48-bit \var{node})
|
||||||
as the \var{fields} argument, or a single 128-bit integer as the \var{int}
|
as the \var{fields} argument, or a single 128-bit integer as the \var{int}
|
||||||
|
@ -109,10 +109,13 @@ when the variant is \constant{RFC_4122}).
|
||||||
The \module{uuid} module defines the following functions
|
The \module{uuid} module defines the following functions
|
||||||
|
|
||||||
\begin{funcdesc}{getnode}{}
|
\begin{funcdesc}{getnode}{}
|
||||||
Get the hardware address as a 48-bit integer. The first time this runs,
|
Get the hardware address as a 48-bit positive integer. The first time this
|
||||||
it may launch a separate program, which could be quite slow. If all
|
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
|
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.
|
number with its eighth bit set to 1 as recommended in RFC 4122. "Hardware
|
||||||
|
address" means the MAC address of a network interface, and on a machine
|
||||||
|
with multiple network interfaces the MAC address of any one of them may
|
||||||
|
be returned.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
\index{getnode}
|
\index{getnode}
|
||||||
|
|
||||||
|
@ -126,10 +129,10 @@ otherwise a random 14-bit sequence number is chosen.
|
||||||
\index{uuid1}
|
\index{uuid1}
|
||||||
|
|
||||||
\begin{funcdesc}{uuid3}{namespace, name}
|
\begin{funcdesc}{uuid3}{namespace, name}
|
||||||
Generate a UUID based upon a MD5 hash of the \var{name} string value
|
Generate a UUID based upon a MD5 hash of the \var{name} string value
|
||||||
drawn from a specified namespace. \var{namespace}
|
drawn from a specified namespace. \var{namespace}
|
||||||
must be one of \constant{NAMESPACE_DNS},
|
must be one of \constant{NAMESPACE_DNS},
|
||||||
\constant{NAMESPACE_URL}, \constant{NAMESPACE_OID},
|
\constant{NAMESPACE_URL}, \constant{NAMESPACE_OID},
|
||||||
or \constant{NAMESPACE_X500}.
|
or \constant{NAMESPACE_X500}.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
\index{uuid3}
|
\index{uuid3}
|
||||||
|
@ -140,15 +143,15 @@ Generate a random UUID.
|
||||||
\index{uuid4}
|
\index{uuid4}
|
||||||
|
|
||||||
\begin{funcdesc}{uuid5}{namespace, name}
|
\begin{funcdesc}{uuid5}{namespace, name}
|
||||||
Generate a UUID based upon a SHA-1 hash of the \var{name} string value
|
Generate a UUID based upon a SHA-1 hash of the \var{name} string value
|
||||||
drawn from a specified namespace. \var{namespace}
|
drawn from a specified namespace. \var{namespace}
|
||||||
must be one of \constant{NAMESPACE_DNS},
|
must be one of \constant{NAMESPACE_DNS},
|
||||||
\constant{NAMESPACE_URL}, \constant{NAMESPACE_OID},
|
\constant{NAMESPACE_URL}, \constant{NAMESPACE_OID},
|
||||||
or \constant{NAMESPACE_X500}.
|
or \constant{NAMESPACE_X500}.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
\index{uuid5}
|
\index{uuid5}
|
||||||
|
|
||||||
The \module{uuid} module defines the following namespace constants
|
The \module{uuid} module defines the following namespace constants
|
||||||
for use with \function{uuid3()} or \function{uuid5()}.
|
for use with \function{uuid3()} or \function{uuid5()}.
|
||||||
|
|
||||||
\begin{datadesc}{NAMESPACE_DNS}
|
\begin{datadesc}{NAMESPACE_DNS}
|
||||||
|
@ -167,7 +170,7 @@ ISO OID namespace UUID.
|
||||||
X.500 DN namespace UUID.
|
X.500 DN namespace UUID.
|
||||||
\end{datadesc}
|
\end{datadesc}
|
||||||
|
|
||||||
The \module{uuid} module defines the following constants
|
The \module{uuid} module defines the following constants
|
||||||
for the possible values of the \member{variant} attribute:
|
for the possible values of the \member{variant} attribute:
|
||||||
|
|
||||||
\begin{datadesc}{RESERVED_NCS}
|
\begin{datadesc}{RESERVED_NCS}
|
||||||
|
|
|
@ -284,7 +284,11 @@ class TestUUID(TestCase):
|
||||||
msg = "different sources disagree on node:\n"
|
msg = "different sources disagree on node:\n"
|
||||||
for s, n in TestUUID.source2node.iteritems():
|
for s, n in TestUUID.source2node.iteritems():
|
||||||
msg += " from source %r, node was %012x\n" % (s, n)
|
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:
|
else:
|
||||||
TestUUID.last_node = node
|
TestUUID.last_node = node
|
||||||
|
|
||||||
|
@ -309,7 +313,7 @@ class TestUUID(TestCase):
|
||||||
def test_random_getnode(self):
|
def test_random_getnode(self):
|
||||||
node = uuid._random_getnode()
|
node = uuid._random_getnode()
|
||||||
self.assert_(0 <= node)
|
self.assert_(0 <= node)
|
||||||
self.assert_(node < 1<<48L)
|
self.assert_(node < (1L <<48))
|
||||||
|
|
||||||
def test_unixdll_getnode(self):
|
def test_unixdll_getnode(self):
|
||||||
import os
|
import os
|
||||||
|
@ -322,10 +326,14 @@ class TestUUID(TestCase):
|
||||||
self.check_node(uuid._windll_getnode(), 'windll')
|
self.check_node(uuid._windll_getnode(), 'windll')
|
||||||
|
|
||||||
def test_getnode(self):
|
def test_getnode(self):
|
||||||
self.check_node(uuid.getnode(), "getnode1")
|
node1 = uuid.getnode()
|
||||||
|
self.check_node(node1, "getnode1")
|
||||||
|
|
||||||
# Test it again to ensure consistency.
|
# 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):
|
def test_uuid1(self):
|
||||||
equal = self.assertEqual
|
equal = self.assertEqual
|
||||||
|
|
15
Lib/uuid.py
15
Lib/uuid.py
|
@ -362,6 +362,10 @@ try:
|
||||||
# hardware address. On Windows 2000 and later, UuidCreate makes a
|
# hardware address. On Windows 2000 and later, UuidCreate makes a
|
||||||
# random UUID and UuidCreateSequential gives a UUID containing the
|
# random UUID and UuidCreateSequential gives a UUID containing the
|
||||||
# hardware address. These routines are provided by the RPC runtime.
|
# 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:
|
try:
|
||||||
lib = ctypes.windll.rpcrt4
|
lib = ctypes.windll.rpcrt4
|
||||||
except:
|
except:
|
||||||
|
@ -389,10 +393,13 @@ def _random_getnode():
|
||||||
_node = None
|
_node = None
|
||||||
|
|
||||||
def getnode():
|
def getnode():
|
||||||
"""Get the hardware address as a 48-bit integer. The first time this
|
"""Get the hardware address as a 48-bit positive integer.
|
||||||
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
|
The first time this runs, it may launch a separate program, which could
|
||||||
48-bit number with its eighth bit set to 1 as recommended in RFC 4122."""
|
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
|
global _node
|
||||||
if _node is not None:
|
if _node is not None:
|
||||||
|
|
Loading…
Reference in New Issue