Skip to content

Commit 5b15134

Browse files
committed
remove references to v7 and v8
1 parent 55edd0c commit 5b15134

File tree

5 files changed

+12
-135
lines changed

5 files changed

+12
-135
lines changed

Doc/library/uuid.rst

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
This module provides immutable :class:`UUID` objects (the :class:`UUID` class)
1414
and the functions :func:`uuid1`, :func:`uuid3`, :func:`uuid4`, :func:`uuid5` for
15-
generating version 1, 3, 4, and 5 UUIDs as specified in :rfc:`4122`.
15+
generating version 1, 3, 4, 5, and 6 UUIDs as specified in :rfc:`4122`.
1616

1717
If all you want is a unique ID, you should probably call :func:`uuid1` or
1818
:func:`uuid4`. Note that :func:`uuid1` may compromise privacy since it creates
@@ -149,11 +149,11 @@ which relays any information about the UUID's safety, using this enumeration:
149149

150150
.. attribute:: UUID.version
151151

152-
The UUID version number (1 through 8, meaningful only when the variant is
152+
The UUID version number (1 through 6, meaningful only when the variant is
153153
:const:`RFC_4122`).
154154

155155
.. versionadded:: 3.14
156-
Added UUID versions 6, 7, and 8.
156+
Added UUID version 6.
157157

158158
.. attribute:: UUID.is_safe
159159

@@ -229,24 +229,6 @@ The :mod:`uuid` module defines the following functions:
229229
.. index:: single: uuid6
230230

231231

232-
.. function:: uuid7()
233-
234-
TODO
235-
236-
.. versionadded:: 3.14
237-
238-
.. index:: single: uuid7
239-
240-
241-
.. function:: uuid8(a=None, b=None, c=None)
242-
243-
TODO
244-
245-
.. versionadded:: 3.14
246-
247-
.. index:: single: uuid8
248-
249-
250232
The :mod:`uuid` module defines the following namespace identifiers for use with
251233
:func:`uuid3` or :func:`uuid5`.
252234

Doc/whatsnew/3.14.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,8 @@ symtable
121121
uuid
122122
----
123123

124-
* Add support for UUID versions 6, 7, and 8 as specified by
125-
:rfc:`9562` to the :mod:`uuid` module:
126-
127-
* :func:`~uuid.uuid6`
128-
* :func:`~uuid.uuid7`
129-
* :func:`~uuid.uuid8`
124+
* Add support for UUID version 6 via :func:`uuid.uuid6` as specified
125+
in :rfc:`9562`.
130126

131127
(Contributed by Bénédikt Tran in :gh:`89083`.)
132128

Lib/test/test_uuid.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import random
21
import unittest
32
from test import support
43
from test.support import import_helper
@@ -11,7 +10,6 @@
1110
import pickle
1211
import sys
1312
import weakref
14-
from itertools import product
1513
from unittest import mock
1614

1715
py_uuid = import_helper.import_fresh_module('uuid', blocked=['_uuid'])
@@ -712,56 +710,6 @@ def test_uuid6(self):
712710
equal(u.fields[4], 0b11000101) # 8 low bits of clock_seq
713711
equal(u.fields[5], fake_node_value)
714712

715-
def test_uuid7(self):
716-
equal = self.assertEqual
717-
u = self.uuid.uuid7()
718-
equal(u.variant, self.uuid.RFC_4122)
719-
equal(u.version, 7)
720-
721-
fake_nanoseconds = 1545052026752910643
722-
# some fake 74 = 12 + 62 random bits speared over 76 bits
723-
# are generated by generating a random 76-bit number, and
724-
# split into chunks of 62 (hi) and 12 (lo) bits.
725-
for _ in range(100):
726-
rand_a = random.getrandbits(12)
727-
rand_b = random.getrandbits(62)
728-
fake_bytes = (rand_b << 12) | rand_a
729-
fake_bytes = fake_bytes.to_bytes(10, byteorder='big')
730-
731-
with mock.patch.object(self.uuid, '_last_timestamp_v7', None), \
732-
mock.patch('time.time_ns', return_value=fake_nanoseconds), \
733-
mock.patch('os.urandom', return_value=fake_bytes):
734-
u = self.uuid.uuid7()
735-
equal(u.variant, self.uuid.RFC_4122)
736-
equal(u.version, 7)
737-
fake_milliseconds = (fake_nanoseconds // 1_000_000) & 0xffffffffffff
738-
equal((u.int >> 80) & 0xffffffffffff, fake_milliseconds)
739-
equal((u.int >> 64) & 0x0fff, rand_a)
740-
equal(u.int & 0x3fffffffffffffff, rand_b)
741-
742-
def test_uuid8(self):
743-
equal = self.assertEqual
744-
u = self.uuid.uuid8()
745-
746-
equal(u.variant, self.uuid.RFC_4122)
747-
equal(u.version, 8)
748-
749-
for (_, hi, mid, lo) in product(
750-
range(10), # repeat 10 times
751-
[None, 0, random.getrandbits(48)],
752-
[None, 0, random.getrandbits(12)],
753-
[None, 0, random.getrandbits(62)],
754-
):
755-
u = self.uuid.uuid8(hi, mid, lo)
756-
equal(u.variant, self.uuid.RFC_4122)
757-
equal(u.version, 8)
758-
if hi is not None:
759-
equal((u.int >> 80) & 0xffffffffffff, hi)
760-
if mid is not None:
761-
equal((u.int >> 64) & 0xfff, mid)
762-
if lo is not None:
763-
equal(u.int & 0x3fffffffffffffff, lo)
764-
765713
@support.requires_fork()
766714
def testIssue8621(self):
767715
# On at least some versions of OSX self.uuid.uuid4 generates

Lib/uuid.py

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
r"""UUID objects (universally unique identifiers) according to RFC 4122.
22
33
This module provides immutable UUID objects (class UUID) and the functions
4-
uuid1(), uuid3(), uuid4(), uuid5(), uuid6(), uuid7(), and uuid8() for
5-
generating version 1 to 8 UUIDs as specified in RFC 4122 (superseeded
6-
by RFC 9562 but still referred to as RFC 4122 for compatibility purposes).
4+
uuid1(), uuid3(), uuid4(), uuid5() and uuid6() for generating version 1, 3,
5+
4, 5, and 6 UUIDs as specified in RFC 4122 (superseeded by RFC 9562 but still
6+
referred to as RFC 4122 for compatibility purposes).
77
88
If all you want is a unique ID, you should probably call uuid1() or uuid4().
99
Note that uuid1() may compromise privacy since it creates a UUID containing
@@ -130,7 +130,7 @@ class UUID:
130130
variant the UUID variant (one of the constants RESERVED_NCS,
131131
RFC_4122, RESERVED_MICROSOFT, or RESERVED_FUTURE)
132132
133-
version the UUID version number (1 through 8, meaningful only
133+
version the UUID version number (1 through 6, meaningful only
134134
when the variant is RFC_4122)
135135
136136
is_safe An enum indicating whether the UUID has been generated in
@@ -215,7 +215,7 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
215215
if not 0 <= int < 1<<128:
216216
raise ValueError('int is out of range (need a 128-bit value)')
217217
if version is not None:
218-
if not 1 <= version <= 8:
218+
if not 1 <= version <= 6:
219219
raise ValueError('illegal version number')
220220
# Set the variant to RFC 4122.
221221
int &= ~(0xc000 << 48)
@@ -763,53 +763,6 @@ def uuid6(node=None, clock_seq=None):
763763
int_uuid_6 |= node & 0xffffffffffff
764764
return UUID(int=int_uuid_6, version=6)
765765

766-
_last_timestamp_v7 = None
767-
768-
def uuid7():
769-
"""Generate a UUID from a Unix timestamp in milliseconds and random bits."""
770-
global _last_timestamp_v7
771-
import time
772-
nanoseconds = time.time_ns()
773-
timestamp_ms = nanoseconds // 1_000_000
774-
if _last_timestamp_v7 is not None and timestamp_ms <= _last_timestamp_v7:
775-
timestamp_ms = _last_timestamp_v7 + 1
776-
_last_timestamp_v7 = timestamp_ms
777-
int_uuid_7 = (timestamp_ms & 0xffffffffffff) << 80
778-
# Ideally, we would have 'rand_a' = first 12 bits of 'rand'
779-
# and 'rand_b' = lowest 62 bits, but it is easier to test
780-
# when we pick 'rand_a' from the lowest bits of 'rand' and
781-
# 'rand_b' from the next 62 bits, ignoring the 6 first bits
782-
# of 'rand'.
783-
rand = int.from_bytes(os.urandom(10)) # 80 random bits (ignore 6 first)
784-
int_uuid_7 |= (rand & 0x0fff) << 64 # rand_a
785-
int_uuid_7 |= (rand >> 12) & 0x3fffffffffffffff # rand_b
786-
return UUID(int=int_uuid_7, version=7)
787-
788-
def uuid8(a=None, b=None, c=None):
789-
"""Generate a UUID from three custom blocks.
790-
791-
'a' is the first 48-bit chunk of the UUID (octets 0-5);
792-
'b' is the mid 12-bit chunk (octets 6-7);
793-
'c' is the last 62-bit chunk (octets 8-15).
794-
795-
When a value is not specified, a random value is generated.
796-
"""
797-
if a is None:
798-
import random
799-
a = random.getrandbits(48)
800-
if b is None:
801-
import random
802-
b = random.getrandbits(12)
803-
if c is None:
804-
import random
805-
c = random.getrandbits(62)
806-
807-
int_uuid_8 = (a & 0xffffffffffff) << 80
808-
int_uuid_8 |= (b & 0xfff) << 64
809-
int_uuid_8 |= c & 0x3fffffffffffffff
810-
return UUID(int=int_uuid_8, version=8)
811-
812-
813766
def main():
814767
"""Run the uuid command line interface."""
815768
uuid_funcs = {
@@ -818,8 +771,6 @@ def main():
818771
"uuid4": uuid4,
819772
"uuid5": uuid5,
820773
"uuid6": uuid6,
821-
"uuid7": uuid7,
822-
"uuid8": uuid8,
823774
}
824775
uuid_namespace_funcs = ("uuid3", "uuid5")
825776
namespaces = {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Add :func:`~uuid.uuid6`, :func:`~uuid.uuid7` and :func:`~uuid.uuid8` to the
2-
:mod:`uuid` module as specified by :rfc:`9562`. Patch by Bénédikt Tran.
1+
Add :func:`uuid.uuid6` for generating UUIDv6 objects as specified in
2+
:rfc:`9562`. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)