summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/hashlib.py29
-rw-r--r--Lib/test/test_hashlib.py6
2 files changed, 20 insertions, 15 deletions
diff --git a/Lib/hashlib.py b/Lib/hashlib.py
index e30c610..4e783a8 100644
--- a/Lib/hashlib.py
+++ b/Lib/hashlib.py
@@ -25,18 +25,18 @@ Choose your hash function wisely. Some have known collision weaknesses.
sha384 and sha512 will be slow on 32 bit platforms.
Hash objects have these methods:
- - update(arg): Update the hash object with the bytes in arg. Repeated calls
- are equivalent to a single call with the concatenation of all
- the arguments.
- - digest(): Return the digest of the bytes passed to the update() method
- so far.
- - hexdigest(): Like digest() except the digest is returned as a unicode
- object of double length, containing only hexadecimal digits.
- - copy(): Return a copy (clone) of the hash object. This can be used to
- efficiently compute the digests of strings that share a common
- initial substring.
-
-For example, to obtain the digest of the string 'Nobody inspects the
+ - update(data): Update the hash object with the bytes in data. Repeated calls
+ are equivalent to a single call with the concatenation of all
+ the arguments.
+ - digest(): Return the digest of the bytes passed to the update() method
+ so far as a bytes object.
+ - hexdigest(): Like digest() except the digest is returned as a string
+ of double length, containing only hexadecimal digits.
+ - copy(): Return a copy (clone) of the hash object. This can be used to
+ efficiently compute the digests of datas that share a common
+ initial substring.
+
+For example, to obtain the digest of the byte string 'Nobody inspects the
spammish repetition':
>>> import hashlib
@@ -130,14 +130,15 @@ def __get_openssl_constructor(name):
def __py_new(name, data=b'', **kwargs):
"""new(name, data=b'', **kwargs) - Return a new hashing object using the
- named algorithm; optionally initialized with data (which must be bytes).
+ named algorithm; optionally initialized with data (which must be
+ a bytes-like object).
"""
return __get_builtin_constructor(name)(data, **kwargs)
def __hash_new(name, data=b'', **kwargs):
"""new(name, data=b'') - Return a new hashing object using the named algorithm;
- optionally initialized with data (which must be bytes).
+ optionally initialized with data (which must be a bytes-like object).
"""
if name in {'blake2b', 'blake2s'}:
# Prefer our blake2 implementation.
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index 0f76b24..c8a873f 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -568,8 +568,12 @@ class HashLibTestCase(unittest.TestCase):
self.assertRaises(ValueError, constructor, node_offset=-1)
self.assertRaises(OverflowError, constructor, node_offset=max_offset+1)
+ self.assertRaises(TypeError, constructor, data=b'')
+ self.assertRaises(TypeError, constructor, string=b'')
+ self.assertRaises(TypeError, constructor, '')
+
constructor(
- string=b'',
+ b'',
key=b'',
salt=b'',
person=b'',