Home | History | Annotate | Download | only in Lib

Lines Matching defs:UUID

1 r"""UUID objects (universally unique identifiers) according to RFC 4122.
3 This module provides immutable UUID objects (class UUID) and the functions
8 Note that uuid1() may compromise privacy since it creates a UUID containing
9 the computer's network address. uuid4() creates a random UUID.
13 >>> import uuid
15 # make a UUID based on the host ID and current time
16 >>> uuid.uuid1() # doctest: +SKIP
17 UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')
19 # make a UUID using an MD5 hash of a namespace UUID and a name
20 >>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
21 UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')
23 # make a random UUID
24 >>> uuid.uuid4() # doctest: +SKIP
25 UUID('16fd2706-8baf-433b-82eb-8c7fada847da')
27 # make a UUID using a SHA-1 hash of a namespace UUID and a name
28 >>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
29 UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')
31 # make a UUID from a string of hex digits (braces and hyphens ignored)
32 >>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}')
34 # convert a UUID to a string of hex digits in standard form
38 # get the raw 16 bytes of the UUID
42 # make a UUID from a 16-byte string
43 >>> uuid.UUID(bytes=x.bytes)
44 UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
69 class UUID:
70 """Instances of the UUID class represent UUIDs as specified in RFC 4122.
71 UUID objects are immutable, hashable, and usable as dictionary keys.
72 Converting a UUID to a string with str() yields something in the form
73 '12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts
84 bytes the UUID as a 16-byte string (containing the six
87 bytes_le the UUID as a 16-byte string (with time_low, time_mid,
90 fields a tuple of the six integer fields of the UUID,
94 time_low the first 32 bits of the UUID
95 time_mid the next 16 bits of the UUID
96 time_hi_version the next 16 bits of the UUID
97 clock_seq_hi_variant the next 8 bits of the UUID
98 clock_seq_low the next 8 bits of the UUID
99 node the last 48 bits of the UUID
104 hex the UUID as a 32-character hexadecimal string
106 int the UUID as a 128-bit integer
108 urn the UUID as a URN as specified in RFC 4122
110 variant the UUID variant (one of the constants RESERVED_NCS,
113 version the UUID version number (1 through 5, meaningful only
116 is_safe An enum indicating whether the UUID has been generated in
124 r"""Create a UUID from either a string of 32 hexadecimal digits,
132 expressions all yield the same UUID:
134 UUID('{12345678-1234-5678-1234-567812345678}')
135 UUID('12345678123456781234567812345678')
136 UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
137 UUID(bytes='\x12\x34\x56\x78'*4)
138 UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
140 UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
141 UUID(int=0x12345678123456781234567812345678)
145 UUID will have its variant and version set according to RFC 4122,
149 indicates whether the UUID has been generated in a way that is safe
157 hex = hex.replace('urn:', '').replace('uuid:', '')
160 raise ValueError('badly formed hexadecimal UUID string')
225 if isinstance(other, UUID):
233 if isinstance(other, UUID):
238 if isinstance(other, UUID):
243 if isinstance(other, UUID):
248 if isinstance(other, UUID):
262 raise TypeError('UUID objects are immutable')
324 return 'urn:uuid:' + str(self)
588 # system routines for UUID generation.
595 _libnames = ['uuid']
624 # On Windows prior to 2000, UuidCreate gives a UUID containing the
626 # random UUID and UuidCreateSequential gives a UUID containing the
641 warnings.warn(f"Could not find fallback ctypes uuid functions: {exc}",
650 return UUID(bytes=uuid_time).node
658 return UUID(bytes=bytes_(_buffer.raw)).node
713 """Generate a UUID from a host ID, sequence number, and the current time.
718 # When the system provides a version-1 UUID generator, use it (but don't
727 return UUID(bytes=uuid_time, is_safe=is_safe)
733 # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
748 return UUID(fields=(time_low, time_mid, time_hi_version,
752 """Generate a UUID from the MD5 hash of a namespace UUID and a name."""
755 return UUID(bytes=hash[:16], version=3)
758 """Generate a random UUID."""
759 return UUID(bytes=os.urandom(16), version=4)
762 """Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
765 return UUID(bytes=hash[:16], version=5)
769 NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
770 NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8')
771 NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8')
772 NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8')