Generate a UUID from the SHA-1 hash of a namespace UUID and a name.
(namespace, name)
| 723 | return UUID(bytes=os.urandom(16), version=4) |
| 724 | |
| 725 | def uuid5(namespace, name): |
| 726 | """Generate a UUID from the SHA-1 hash of a namespace UUID and a name.""" |
| 727 | from hashlib import sha1 |
| 728 | hash = sha1(namespace.bytes + bytes(name, "utf-8")).digest() |
| 729 | return UUID(bytes=hash[:16], version=5) |
| 730 | |
| 731 | # The following standard UUIDs are for use with uuid3() or uuid5(). |
| 732 |