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()
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')
55 class UUID(object):
56 """Instances of the UUID class represent UUIDs as specified in RFC 4122.
57 UUID objects are immutable, hashable, and usable as dictionary keys.
58 Converting a UUID to a string with str() yields something in the form
59 '12345678-1234-1234-1234-123456789abc'. The UUID constructor accepts
70 bytes the UUID as a 16-byte string (containing the six
73 bytes_le the UUID as a 16-byte string (with time_low, time_mid,
76 fields a tuple of the six integer fields of the UUID,
80 time_low the first 32 bits of the UUID
81 time_mid the next 16 bits of the UUID
82 time_hi_version the next 16 bits of the UUID
83 clock_seq_hi_variant the next 8 bits of the UUID
84 clock_seq_low the next 8 bits of the UUID
85 node the last 48 bits of the UUID
90 hex the UUID as a 32-character hexadecimal string
92 int the UUID as a 128-bit integer
94 urn the UUID as a URN as specified in RFC 4122
96 variant the UUID variant (one of the constants RESERVED_NCS,
99 version the UUID version number (1 through 5, meaningful only
105 r"""Create a UUID from either a string of 32 hexadecimal digits,
113 expressions all yield the same UUID:
115 UUID('{12345678-1234-5678-1234-567812345678}')
116 UUID('12345678123456781234567812345678')
117 UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
118 UUID(bytes='\x12\x34\x56\x78'*4)
119 UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
121 UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
122 UUID(int=0x12345678123456781234567812345678)
126 UUID will have its variant and version set according to RFC 4122,
133 hex = hex.replace('urn:', '').replace('uuid:', '')
136 raise ValueError('badly formed hexadecimal UUID string')
183 if isinstance(other, UUID):
194 return 'UUID(%r)' % str(self)
197 raise TypeError('UUID objects are immutable')
273 return 'urn:uuid:' + str(self)
456 # If ctypes is available, use it to find system routines for UUID generation.
464 _libnames = ['uuid']
489 # On Windows prior to 2000, UuidCreate gives a UUID containing the
491 # random UUID and UuidCreateSequential gives a UUID containing the
510 return UUID(bytes=_buffer.raw).node
516 return UUID(bytes=_buffer.raw).node
562 """Generate a UUID from a host ID, sequence number, and the current time.
567 # When the system provides a version-1 UUID generator, use it (but don't
572 return UUID(bytes=_buffer.raw)
578 # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
593 return UUID(fields=(time_low, time_mid, time_hi_version,
597 """Generate a UUID from the MD5 hash of a namespace UUID and a name."""
600 return UUID(bytes=hash[:16], version=3)
603 """Generate a random UUID."""
604 return UUID(bytes=os.urandom(16), version=4)
607 """Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
610 return UUID(bytes=hash[:16], version=5)
614 NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
615 NAMESPACE_URL = UUID('6ba7b811-9dad-11d1-80b4-00c04fd430c8')
616 NAMESPACE_OID = UUID('6ba7b812-9dad-11d1-80b4-00c04fd430c8')
617 NAMESPACE_X500 = UUID('6ba7b814-9dad-11d1-80b4-00c04fd430c8')