Generate a UUID from the SHA-1 hash of a namespace UUID and a name.
(namespace, name)
| 780 | return UUID._from_int(int_uuid_4) |
| 781 | |
| 782 | def uuid5(namespace, name): |
| 783 | """Generate a UUID from the SHA-1 hash of a namespace UUID and a name.""" |
| 784 | if isinstance(name, str): |
| 785 | name = bytes(name, "utf-8") |
| 786 | import hashlib |
| 787 | h = hashlib.sha1(namespace.bytes + name, usedforsecurity=False) |
| 788 | int_uuid_5 = int.from_bytes(h.digest()[:16]) |
| 789 | int_uuid_5 &= _RFC_4122_CLEARFLAGS_MASK |
| 790 | int_uuid_5 |= _RFC_4122_VERSION_5_FLAGS |
| 791 | return UUID._from_int(int_uuid_5) |
| 792 | |
| 793 | |
| 794 | _last_timestamp_v6 = None |