codekingpro/portable-devtools
114k
1import sys
2from typing import Final
3from uuid import (
4 NAMESPACE_DNS,
5 NAMESPACE_OID,
6 NAMESPACE_URL,
7 NAMESPACE_X500,
8 RESERVED_FUTURE,
9 RESERVED_MICROSOFT,
10 RESERVED_NCS,
11 RFC_4122,
12 UUID,
13 SafeUUID,
14 getnode,
15)
16
17def uuid1(node: int | None = None, clock_seq: int | None = None) -> UUID:
18 """Generate a UUID from a host ID, sequence number, and the current time.
19 If 'node' is not given, getnode() is used to obtain the hardware
20 address. If 'clock_seq' is given, it is used as the sequence number;
21 otherwise a random 14-bit sequence number is chosen."""
22 ...
23
24if sys.version_info >= (3, 12):
25 def uuid3(namespace: UUID, name: str | bytes) -> UUID:
26 """Generate a UUID from the MD5 hash of a namespace UUID and a name."""
27 ...
28
29else:
30 def uuid3(namespace: UUID, name: str) -> UUID:
31 """Generate a UUID from the MD5 hash of a namespace UUID and a name."""
32 ...
33
34def uuid4() -> UUID:
35 """Generate a random UUID."""
36 ...
37
38if sys.version_info >= (3, 12):
39 def uuid5(namespace: UUID, name: str | bytes) -> UUID:
40 """Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
41 ...
42else:
43 def uuid5(namespace: UUID, name: str) -> UUID:
44 """Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
45 ...
46
47def uuid6(node: int | None = None, timestamp: int | None = None) -> UUID:
48 """Generate a version 6 UUID using the given timestamp and a host ID.
49 This is similar to version 1 UUIDs,
50 except that it is lexicographically sortable by timestamp.
51 """
52 ...
53
54def uuid7(timestamp: int | None = None, nanos: int | None = None) -> UUID:
55 """Generate a version 7 UUID using a time value and random bytes."""
56 ...
57
58def uuid8(bytes: bytes) -> UUID:
59 """Generate a custom UUID comprised almost entirely of user-supplied bytes."""
60 ...
61
62NIL: Final[UUID]
63MAX: Final[UUID]
64
65__all__ = [
66 "MAX",
67 "NAMESPACE_DNS",
68 "NAMESPACE_OID",
69 "NAMESPACE_URL",
70 "NAMESPACE_X500",
71 "NIL",
72 "RESERVED_FUTURE",
73 "RESERVED_MICROSOFT",
74 "RESERVED_NCS",
75 "RFC_4122",
76 "UUID",
77 "SafeUUID",
78 "getnode",
79]
80 