Reserved for future definition.
+The :mod:`uuid` module defines the special Nil and Max UUID values:
+
+
+.. data:: NIL
+
+ A special form of UUID that is specified to have all 128 bits set to zero
+ according to :rfc:`RFC 9562, §5.9 <9562#section-5.9>`.
+
+ .. versionadded:: next
+
+
+.. data:: MAX
+
+ A special form of UUID that is specified to have all 128 bits set to one
+ according to :rfc:`RFC 9562, §5.10 <9562#section-5.10>`.
+
+ .. versionadded:: next
+
+
.. seealso::
:rfc:`9562` - A Universally Unique IDentifier (UUID) URN Namespace
>>> uuid.UUID(bytes=x.bytes)
UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
+ >>> # get the Nil UUID
+ >>> uuid.NIL
+ UUID('00000000-0000-0000-0000-000000000000')
+
+ >>> # get the Max UUID
+ >>> uuid.MAX
+ UUID('ffffffff-ffff-ffff-ffff-ffffffffffff')
+
.. _uuid-cli-example:
class BaseTestUUID:
uuid = None
+ def test_nil_uuid(self):
+ nil_uuid = self.uuid.NIL
+
+ s = '00000000-0000-0000-0000-000000000000'
+ i = 0
+ self.assertEqual(nil_uuid, self.uuid.UUID(s))
+ self.assertEqual(nil_uuid, self.uuid.UUID(int=i))
+ self.assertEqual(nil_uuid.int, i)
+ self.assertEqual(str(nil_uuid), s)
+ # The Nil UUID falls within the range of the Apollo NCS variant as per
+ # RFC 9562.
+ # See https://www.rfc-editor.org/rfc/rfc9562.html#section-5.9-4
+ self.assertEqual(nil_uuid.variant, self.uuid.RESERVED_NCS)
+ # A version field of all zeros is "Unused" in RFC 9562, but the version
+ # field also only applies to the 10xx variant, i.e. the variant
+ # specified in RFC 9562. As such, because the Nil UUID falls under a
+ # different variant, its version is considered undefined.
+ # See https://www.rfc-editor.org/rfc/rfc9562.html#table2
+ self.assertIsNone(nil_uuid.version)
+
+ def test_max_uuid(self):
+ max_uuid = self.uuid.MAX
+
+ s = 'ffffffff-ffff-ffff-ffff-ffffffffffff'
+ i = (1 << 128) - 1
+ self.assertEqual(max_uuid, self.uuid.UUID(s))
+ self.assertEqual(max_uuid, self.uuid.UUID(int=i))
+ self.assertEqual(max_uuid.int, i)
+ self.assertEqual(str(max_uuid), s)
+ # The Max UUID falls within the range of the "yet-to-be defined" future
+ # UUID variant as per RFC 9562.
+ # See https://www.rfc-editor.org/rfc/rfc9562.html#section-5.10-4
+ self.assertEqual(max_uuid.variant, self.uuid.RESERVED_FUTURE)
+ # A version field of all ones is "Reserved for future definition" in
+ # RFC 9562, but the version field also only applies to the 10xx
+ # variant, i.e. the variant specified in RFC 9562. As such, because the
+ # Max UUID falls under a different variant, its version is considered
+ # undefined.
+ # See https://www.rfc-editor.org/rfc/rfc9562.html#table2
+ self.assertIsNone(max_uuid.version)
+
def test_safe_uuid_enum(self):
class CheckedSafeUUID(enum.Enum):
safe = 0
# make a UUID from a 16-byte string
>>> uuid.UUID(bytes=x.bytes)
UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
+
+ # get the Nil UUID
+ >>> uuid.NIL
+ UUID('00000000-0000-0000-0000-000000000000')
+
+ # get the Max UUID
+ >>> uuid.MAX
+ UUID('ffffffff-ffff-ffff-ffff-ffffffffffff')
"""
import os
NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8')
NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8')
+# RFC 9562 Sections 5.9 and 5.10 define the special Nil and Max UUID formats.
+
+NIL = UUID('00000000-0000-0000-0000-000000000000')
+MAX = UUID('ffffffff-ffff-ffff-ffff-ffffffffffff')
+
if __name__ == "__main__":
main()