]> granicus.if.org Git - python/commitdiff
Bug #1541863: uuid.uuid1 failed to generate unique identifiers
authorMartin v. Löwis <martin@v.loewis.de>
Fri, 18 Aug 2006 03:40:13 +0000 (03:40 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Fri, 18 Aug 2006 03:40:13 +0000 (03:40 +0000)
on systems with low clock resolution.

Lib/test/test_uuid.py
Lib/uuid.py
Misc/NEWS

index 06ec51da799e62fc7a8cb15647cfcd8d29cd0257..90671be05d4acc24e12c33063c3838a6b6f8ec93 100644 (file)
@@ -429,7 +429,7 @@ class TestUUID(TestCase):
 
         # Make sure the generated UUIDs are actually unique.
         uuids = {}
-        for u in [uuid.uuid1() for i in range(1000)]:
+        for u in [uuid.uuid4() for i in range(1000)]:
             uuids[u] = 1
         equal(len(uuids.keys()), 1000)
 
index 684bbeb9468250feab75d46a6ea49653be4db779..ae3da25ca55771f9b6d55794b969b6ff9659eab2 100644 (file)
@@ -488,8 +488,8 @@ def uuid1(node=None, clock_seq=None):
     # 0x01b21dd213814000 is the number of 100-ns intervals between the
     # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
     timestamp = int(nanoseconds/100) + 0x01b21dd213814000L
-    if timestamp == _last_timestamp:
-        timestamp += 1
+    if timestamp <= _last_timestamp:
+        timestamp = _last_timestamp + 1
     _last_timestamp = timestamp
     if clock_seq is None:
         import random
index d9bff35ba77d0eeb1b5691d0ac6c8bd4ec5965b6..1f96071fc8cce9d67fc805af1b057523d98c5ca7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,12 @@ What's New in Python 2.5 ?
 
 *Release date: XX-SEP-2006*
 
+Library
+-------
+
+- Bug #1541863: uuid.uuid1 failed to generate unique identifiers
+  on systems with low clock resolution.
+
 Build
 -----