diff options
author | Guido van Rossum <guido@python.org> | 2007-08-27 23:09:25 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-27 23:09:25 (GMT) |
commit | e22905a06c0632cb1c5fefcbbb51c0675ae21bba (patch) | |
tree | 0e5fc8d57800a489e01468f9b024663087ab5fbd /Lib/hashlib.py | |
parent | 25a29a9534ea8bbfce297eb92c82741833fe04eb (diff) | |
download | cpython-e22905a06c0632cb1c5fefcbbb51c0675ae21bba.zip cpython-e22905a06c0632cb1c5fefcbbb51c0675ae21bba.tar.gz cpython-e22905a06c0632cb1c5fefcbbb51c0675ae21bba.tar.bz2 |
More changes needed to make things work once bytes and str are truly divorced.
Diffstat (limited to 'Lib/hashlib.py')
-rw-r--r-- | Lib/hashlib.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/Lib/hashlib.py b/Lib/hashlib.py index af67114..1d0e647 100644 --- a/Lib/hashlib.py +++ b/Lib/hashlib.py @@ -6,9 +6,9 @@ __doc__ = """hashlib module - A common interface to many hash functions. -new(name, string='') - returns a new hash object implementing the - given hash function; initializing the hash - using the given string data. +new(name, data=b'') - returns a new hash object implementing the + given hash function; initializing the hash + using the given binary data. Named constructor functions are also available, these are much faster than using new(): @@ -39,14 +39,14 @@ spammish repetition': >>> import hashlib >>> m = hashlib.md5() - >>> m.update("Nobody inspects") - >>> m.update(" the spammish repetition") + >>> m.update(b"Nobody inspects") + >>> m.update(b" the spammish repetition") >>> m.digest() - '\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9' + b'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9' More condensed: - >>> hashlib.sha224("Nobody inspects the spammish repetition").hexdigest() + >>> hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest() 'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2' """ @@ -77,25 +77,25 @@ def __get_builtin_constructor(name): raise ValueError, "unsupported hash type" -def __py_new(name, string=''): - """new(name, string='') - Return a new hashing object using the named algorithm; - optionally initialized with a string. +def __py_new(name, data=b''): + """new(name, data='') - Return a new hashing object using the named algorithm; + optionally initialized with data (which must be bytes). """ - return __get_builtin_constructor(name)(string) + return __get_builtin_constructor(name)(data) -def __hash_new(name, string=''): - """new(name, string='') - Return a new hashing object using the named algorithm; - optionally initialized with a string. +def __hash_new(name, data=b''): + """new(name, data=b'') - Return a new hashing object using the named algorithm; + optionally initialized with data (which must be bytes). """ try: - return _hashlib.new(name, string) + return _hashlib.new(name, data) except ValueError: # If the _hashlib module (OpenSSL) doesn't support the named # hash, try using our builtin implementations. # This allows for SHA224/256 and SHA384/512 support even though # the OpenSSL library prior to 0.9.8 doesn't provide them. - return __get_builtin_constructor(name)(string) + return __get_builtin_constructor(name)(data) try: |