Lines Matching full: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')
84 class UUID: class
85 """Instances of the UUID class represent UUIDs as specified in RFC 4122.
86 UUID objects are immutable, hashable, and usable as dictionary keys.
87 Converting a UUID to a string with str() yields something in the form
88 '12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts
99 bytes the UUID as a 16-byte string (containing the six
102 bytes_le the UUID as a 16-byte string (with time_low, time_mid,
105 fields a tuple of the six integer fields of the UUID,
109 time_low the first 32 bits of the UUID
110 time_mid the next 16 bits of the UUID
111 time_hi_version the next 16 bits of the UUID
112 clock_seq_hi_variant the next 8 bits of the UUID
113 clock_seq_low the next 8 bits of the UUID
114 node the last 48 bits of the UUID
119 hex the UUID as a 32-character hexadecimal string
121 int the UUID as a 128-bit integer
123 urn the UUID as a URN as specified in RFC 4122
125 variant the UUID variant (one of the constants RESERVED_NCS,
128 version the UUID version number (1 through 5, meaningful only
131 is_safe An enum indicating whether the UUID has been generated in
141 r"""Create a UUID from either a string of 32 hexadecimal digits,
149 expressions all yield the same UUID:
151 UUID('{12345678-1234-5678-1234-567812345678}')
152 UUID('12345678123456781234567812345678')
153 UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
154 UUID(bytes='\x12\x34\x56\x78'*4)
155 UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
157 UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
158 UUID(int=0x12345678123456781234567812345678)
162 UUID will have its variant and version set according to RFC 4122,
166 indicates whether the UUID has been generated in a way that is safe
174 hex = hex.replace('urn:', '').replace('uuid:', '')
177 raise ValueError('badly formed hexadecimal UUID string')
240 if isinstance(other, UUID):
248 if isinstance(other, UUID):
253 if isinstance(other, UUID):
258 if isinstance(other, UUID):
263 if isinstance(other, UUID):
277 raise TypeError('UUID objects are immutable')
339 return 'urn:uuid:' + str(self)
504 # be used as basis for an uuid
591 return UUID(bytes=uuid_time).node
597 return UUID(bytes_le=uuid_bytes).node
667 """Generate a UUID from a host ID, sequence number, and the current time.
672 # When the system provides a version-1 UUID generator, use it (but don't
680 return UUID(bytes=uuid_time, is_safe=is_safe)
686 # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
701 return UUID(fields=(time_low, time_mid, time_hi_version,
705 """Generate a UUID from the MD5 hash of a namespace UUID and a name."""
711 return UUID(bytes=digest[:16], version=3)
714 """Generate a random UUID."""
715 return UUID(bytes=os.urandom(16), version=4)
718 """Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
721 return UUID(bytes=hash[:16], version=5)
725 NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
726 NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8')
727 NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8')
728 NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8')