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()
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()
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')
53 class UUID(object):
54 """Instances of the UUID class represent UUIDs as specified in RFC 4122.
55 UUID objects are immutable, hashable, and usable as dictionary keys.
56 Converting a UUID to a string with str() yields something in the form
57 '12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts
68 bytes the UUID as a 16-byte string (containing the six
71 bytes_le the UUID as a 16-byte string (with time_low, time_mid,
74 fields a tuple of the six integer fields of the UUID,
78 time_low the first 32 bits of the UUID
79 time_mid the next 16 bits of the UUID
80 time_hi_version the next 16 bits of the UUID
81 clock_seq_hi_variant the next 8 bits of the UUID
82 clock_seq_low the next 8 bits of the UUID
83 node the last 48 bits of the UUID
88 hex the UUID as a 32-character hexadecimal string
90 int the UUID as a 128-bit integer
92 urn the UUID as a URN as specified in RFC 4122
94 variant the UUID variant (one of the constants RESERVED_NCS,
97 version the UUID version number (1 through 5, meaningful only
103 r"""Create a UUID from either a string of 32 hexadecimal digits,
111 expressions all yield the same UUID:
113 UUID('{12345678-1234-5678-1234-567812345678}')
114 UUID('12345678123456781234567812345678')
115 UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
116 UUID(bytes='\x12\x34\x56\x78'*4)
117 UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
119 UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
120 UUID(int=0x12345678123456781234567812345678)
124 UUID will have its variant and version set according to RFC 4122,
131 hex = hex.replace('urn:', '').replace('uuid:', '')
134 raise ValueError('badly formed hexadecimal UUID string')
181 if isinstance(other, UUID):
192 return 'UUID(%r)' % str(self)
195 raise TypeError('UUID objects are immutable')
271 return 'urn:uuid:' + str(self)
395 # If ctypes is available, use it to find system routines for UUID generation.
402 for libname in ['uuid', 'c']:
425 # On Windows prior to 2000, UuidCreate gives a UUID containing the
427 # random UUID and UuidCreateSequential gives a UUID containing the
446 return UUID(bytes=_buffer.raw).node
452 return UUID(bytes=_buffer.raw).node
491 """Generate a UUID from a host ID, sequence number, and the current time.
496 # When the system provides a version-1 UUID generator, use it (but don't
501 return UUID(bytes=_buffer.raw)
507 # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
522 return UUID(fields=(time_low, time_mid, time_hi_version,
526 """Generate a UUID from the MD5 hash of a namespace UUID and a name."""
529 return UUID(bytes=hash[:16], version=3)
532 """Generate a random UUID."""
534 # When the system provides a version-4 UUID generator, use it.
538 return UUID(bytes=_buffer.raw)
543 return UUID(bytes=os.urandom(16), version=4)
547 return UUID(bytes=bytes, version=4)
550 """Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
553 return UUID(bytes=hash[:16], version=5)
557 NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
558 NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8')
559 NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8')
560 NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8')