mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #22341: Drop Python 2 workaround and document CRC initial value
Also align the parameter naming in binascii to be consistent with zlib.
This commit is contained in:
parent
7dda421bff
commit
b82032f935
6 changed files with 39 additions and 58 deletions
|
@ -110,15 +110,16 @@ The :mod:`binascii` module defines the following functions:
|
|||
possibly the last fragment).
|
||||
|
||||
|
||||
.. function:: crc_hqx(data, crc)
|
||||
.. function:: crc_hqx(data, value)
|
||||
|
||||
Compute the binhex4 crc value of *data*, starting with an initial *crc* and
|
||||
returning the result.
|
||||
Compute the binhex4 crc value of *data*, starting with *value* as the
|
||||
initial crc, and return the result.
|
||||
|
||||
|
||||
.. function:: crc32(data[, crc])
|
||||
.. function:: crc32(data[, value])
|
||||
|
||||
Compute CRC-32, the 32-bit checksum of data, starting with an initial crc. This
|
||||
Compute CRC-32, the 32-bit checksum of *data*, starting with an
|
||||
initial CRC of *value*. The default initial CRC is zero. The algorithm
|
||||
is consistent with the ZIP file checksum. Since the algorithm is designed for
|
||||
use as a checksum algorithm, it is not suitable for use as a general hash
|
||||
algorithm. Use as follows::
|
||||
|
@ -126,15 +127,13 @@ The :mod:`binascii` module defines the following functions:
|
|||
print(binascii.crc32(b"hello world"))
|
||||
# Or, in two pieces:
|
||||
crc = binascii.crc32(b"hello")
|
||||
crc = binascii.crc32(b" world", crc) & 0xffffffff
|
||||
crc = binascii.crc32(b" world", crc)
|
||||
print('crc32 = {:#010x}'.format(crc))
|
||||
|
||||
.. note::
|
||||
To generate the same numeric value across all Python versions and
|
||||
platforms use crc32(data) & 0xffffffff. If you are only using
|
||||
the checksum in packed binary format this is not necessary as the
|
||||
return value is the correct 32bit binary representation
|
||||
regardless of sign.
|
||||
.. versionchanged:: 3.0
|
||||
The result is always unsigned.
|
||||
To generate the same numeric value across all Python versions and
|
||||
platforms, use ``crc32(data) & 0xffffffff``.
|
||||
|
||||
|
||||
.. function:: b2a_hex(data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue