Change hashlib to return bytes from digest() instead of str8.

This commit is contained in:
Guido van Rossum 2007-07-09 14:29:40 +00:00
parent 867bcbcd6d
commit 5ed033b5a2
5 changed files with 32 additions and 29 deletions

View file

@ -528,7 +528,7 @@ def uuid3(namespace, name):
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
from hashlib import md5
hash = md5(namespace.bytes + bytes(name, "utf-8")).digest()
return UUID(bytes=bytes_(hash[:16]), version=3)
return UUID(bytes=hash[:16], version=3)
def uuid4():
"""Generate a random UUID."""
@ -551,7 +551,7 @@ def uuid5(namespace, name):
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
from hashlib import sha1
hash = sha1(namespace.bytes + bytes(name, "utf-8")).digest()
return UUID(bytes=bytes_(hash[:16]), version=5)
return UUID(bytes=hash[:16], version=5)
# The following standard UUIDs are for use with uuid3() or uuid5().