8000 gh-136565: Improve and amend `hashlib.__doc__` (#136566) · python/cpython@83d04a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 83d04a2

Browse files
authored
gh-136565: Improve and amend hashlib.__doc__ (#136566)
1 parent c7d24b8 commit 83d04a2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Lib/hashlib.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed to PSF under a Contributor Agreement.
33
#
44

5-
__doc__ = """hashlib module - A common interface to many hash functions.
5+
__doc__ = r"""hashlib module - A common interface to many hash functions.
66
77
new(name, data=b'', **kwargs) - returns a new hash object implementing the
88
given hash function; initializing the hash
@@ -12,7 +12,7 @@
1212
than using new(name):
1313
1414
md5(), sha1(), sha224(), sha256(), sha384(), sha512(), blake2b(), blake2s(),
15-
sha3_224, sha3_256, sha3_384, sha3_512, shake_128, and shake_256.
15+
sha3_224(), sha3_256(), sha3_384(), sha3_512(), shake_128(), and shake_256().
1616
1717
More algorithms may be available on your platform but the above are guaranteed
1818
to exist. See the algorithms_guaranteed and algorithms_available attributes
@@ -21,8 +21,8 @@
2121
NOTE: If you want the adler32 or crc32 hash functions they are available in
2222
the zlib module.
2323
24-
Choose your hash function wisely. Some have known collision weaknesses.
25-
sha384 and sha512 will be slow on 32 bit platforms.
24+
Choose your hash function wisely. Some have known collision weaknesses,
25+
while others may be slower depending on the CPU architecture.
2626
2727
Hash objects have these methods:
2828
- update(data): Update the hash object with the bytes in data. Repeated calls
@@ -36,20 +36,20 @@
3636
efficiently compute the digests of data that share a common
3737
initial substring.
3838
39-
For example, to obtain the digest of the byte string 'Nobody inspects the
40-
spammish repetition':
39+
Assuming that Python has been built with MD5 support, the following computes
40+
the MD5 digest of the byte string b'Nobody inspects the spammish repetition':
4141
4242
>>> import hashlib
4343
>>> m = hashlib.md5()
4444
>>> m.update(b"Nobody inspects")
4545
>>> m.update(b" the spammish repetition")
4646
>>> m.digest()
47-
b'\\xbbd\\x9c\\x83\\xdd\\x1e\\xa5\\xc9\\xd9\\xde\\xc9\\xa1\\x8d\\xf0\\xff\\xe9'
47+
b'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9'
4848
4949
More condensed:
5050
51-
>>> hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest()
52-
'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'
51+
>>> hashlib.md5(b"Nobody inspects the spammish repetition").hexdigest()
52+
'bb649c83dd1ea5c9d9dec9a18df0ffe9'
5353
5454
"""
5555

@@ -203,7 +203,7 @@ def file_digest(fileobj, digest, /, *, _bufsize=2**18):
203203
*digest* must either be a hash algorithm name as a *str*, a hash
204204
constructor, or a callable that returns a hash object.
205205
"""
206-
# On Linux we could use AF_ALG sockets and sendfile() to archive zero-copy
206+
# On Linux we could use AF_ALG sockets and sendfile() to achieve zero-copy
207207
# hashing with hardware acceleration.
208208
if isinstance(digest, str):
209209
digestobj 37AD = new(digest)

0 commit comments

Comments
 (0)
0