summaryrefslogtreecommitdiffstats
path: root/Lib/uuid.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-12-18 10:45:13 (GMT)
committerGitHub <noreply@github.com>2018-12-18 10:45:13 (GMT)
commit62a68b762a479a72c3defba9ace5f72a0063c5c6 (patch)
treedcadb35bdadeaae4cd99842e65e2a3bf412336ec /Lib/uuid.py
parent1dd035954bb03c41b954ebbd63969b4bcb0e106e (diff)
downloadcpython-62a68b762a479a72c3defba9ace5f72a0063c5c6.zip
cpython-62a68b762a479a72c3defba9ace5f72a0063c5c6.tar.gz
cpython-62a68b762a479a72c3defba9ace5f72a0063c5c6.tar.bz2
bpo-31784: Use time.time_ns() in uuid.uuid1() (GH-11189)
uuid.uuid1() now calls time.time_ns() rather than int(time.time() * 1e9). Replace also int(nanoseconds/100) with nanoseconds // 100. Add an unit test.
Diffstat (limited to 'Lib/uuid.py')
-rw-r--r--Lib/uuid.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/uuid.py b/Lib/uuid.py
index 073ca71..4468d4a 100644
--- a/Lib/uuid.py
+++ b/Lib/uuid.py
@@ -728,10 +728,10 @@ def uuid1(node=None, clock_seq=None):
global _last_timestamp
import time
- nanoseconds = int(time.time() * 1e9)
+ nanoseconds = time.time_ns()
# 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) + 0x01b21dd213814000
+ timestamp = nanoseconds // 100 + 0x01b21dd213814000
if _last_timestamp is not None and timestamp <= _last_timestamp:
timestamp = _last_timestamp + 1
_last_timestamp = timestamp