Skip to content

Commit a8aba33

Browse files
authored
Merge branch 'main' into glob-duplicates
2 parents 98ce46b + 58f0bda commit a8aba33

File tree

174 files changed

+3356
-2091
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+3356
-2091
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,8 @@ jobs:
235235
run: brew install pkg-config [email protected] xz gdbm tcl-tk
236236
- name: Configure CPython
237237
run: |
238-
CFLAGS="-I$(brew --prefix gdbm)/include -I$(brew --prefix xz)/include" \
239-
LDFLAGS="-L$(brew --prefix gdbm)/lib -I$(brew --prefix xz)/lib" \
240-
PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
238+
GDBM_CFLAGS="-I$(brew --prefix gdbm)/include" \
239+
GDBM_LIBS="-L$(brew --prefix gdbm)/lib -lgdbm" \
241240
./configure \
242241
--config-cache \
243242
--with-pydebug \

Doc/c-api/import.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Importing Modules
3838
to per-module locks for most purposes, so this function's special
3939
behaviour isn't needed anymore.
4040
41+
.. deprecated-removed:: 3.13 3.15
42+
Use :c:func:`PyImport_ImportModule` instead.
43+
4144
4245
.. c:function:: PyObject* PyImport_ImportModuleEx(const char *name, PyObject *globals, PyObject *locals, PyObject *fromlist)
4346

Doc/howto/enum.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,16 @@ from that module.
517517
nested in other classes.
518518

519519
It is possible to modify how enum members are pickled/unpickled by defining
520-
:meth:`__reduce_ex__` in the enumeration class.
520+
:meth:`__reduce_ex__` in the enumeration class. The default method is by-value,
521+
but enums with complicated values may want to use by-name::
522+
523+
>>> class MyEnum(Enum):
524+
... __reduce_ex__ = enum.pickle_by_enum_name
525+
526+
.. note::
527+
528+
Using by-name for flags is not recommended, as unnamed aliases will
529+
not unpickle.
521530

522531

523532
Functional API

Doc/library/array.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Notes:
5757
``Py_UNICODE``. This change doesn't affect its behavior because
5858
``Py_UNICODE`` is alias of ``wchar_t`` since Python 3.3.
5959

60-
.. deprecated-removed:: 3.3 4.0
60+
.. deprecated-removed:: 3.3 3.16
6161
Please migrate to ``'w'`` typecode.
6262

6363

Doc/library/decimal.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ are also included in the pure Python version for compatibility.
14971497

14981498
The value is ``True``. Deprecated, because Python now always has threads.
14991499

1500-
.. deprecated:: 3.9
1500+
.. deprecated:: 3.9
15011501

15021502
.. data:: HAVE_CONTEXTVAR
15031503

Doc/library/dis.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,25 @@ details of bytecode instructions as :class:`Instruction` instances:
342342
human readable name for operation
343343

344344

345+
.. data:: baseopcode
346+
347+
numeric code for the base operation if operation is specialized;
348+
otherwise equal to :data:`opcode`
349+
350+
351+
.. data:: baseopname
352+
353+
human readable name for the base operation if operation is specialized;
354+
otherwise equal to :data:`opname`
355+
356+
345357
.. data:: arg
346358

347359
numeric argument to operation (if any), otherwise ``None``
348360

361+
.. data:: oparg
362+
363+
alias for :data:`arg`
349364

350365
.. data:: argval
351366

@@ -363,6 +378,22 @@ details of bytecode instructions as :class:`Instruction` instances:
363378
start index of operation within bytecode sequence
364379

365380

381+
.. data:: start_offset
382+
383+
start index of operation within bytecode sequence, including prefixed
384+
``EXTENDED_ARG`` operations if present; otherwise equal to :data:`offset`
385+
386+
387+
.. data:: cache_offset
388+
389+
start index of the cache entries following the operation
390+
391+
392+
.. data:: end_offset
393+
394+
end index of the cache entries following the operation
395+
396+
366397
.. data:: starts_line
367398

368399
line started by this opcode (if any), otherwise ``None``
@@ -373,6 +404,12 @@ details of bytecode instructions as :class:`Instruction` instances:
373404
``True`` if other code jumps to here, otherwise ``False``
374405

375406

407+
.. data:: jump_target
408+
409+
bytecode index of the jump target if this is a jump operation,
410+
otherwise ``None``
411+
412+
376413
.. data:: positions
377414

378415
:class:`dis.Positions` object holding the
@@ -384,6 +421,11 @@ details of bytecode instructions as :class:`Instruction` instances:
384421

385422
Field ``positions`` is added.
386423

424+
.. versionchanged:: 3.13
425+
426+
Added fields ``start_offset``, ``cache_offset``, ``end_offset``,
427+
``baseopname``, ``baseopcode``, ``jump_target`` and ``oparg``.
428+
387429

388430
.. class:: Positions
389431

Doc/library/hashlib.rst

Lines changed: 96 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
.. index::
1313
single: message digest, MD5
14-
single: secure hash algorithm, SHA1, SHA224, SHA256, SHA384, SHA512
14+
single: secure hash algorithm, SHA1, SHA2, SHA224, SHA256, SHA384, SHA512, SHA3, Shake, Blake2
1515

1616
.. testsetup::
1717

@@ -22,7 +22,8 @@
2222

2323
This module implements a common interface to many different secure hash and
2424
message digest algorithms. Included are the FIPS secure hash algorithms SHA1,
25-
SHA224, SHA256, SHA384, and SHA512 (defined in FIPS 180-2) as well as RSA's MD5
25+
SHA224, SHA256, SHA384, SHA512, (defined in `the FIPS 180-4 standard`_),
26+
the SHA-3 series (defined in `the FIPS 202 standard`_) as well as RSA's MD5
2627
algorithm (defined in internet :rfc:`1321`). The terms "secure hash" and
2728
"message digest" are interchangeable. Older algorithms were called message
2829
digests. The modern term is secure hash.
@@ -32,50 +33,50 @@ digests. The modern term is secure hash.
3233
If you want the adler32 or crc32 hash functions, they are available in
3334
the :mod:`zlib` module.
3435

35-
.. warning::
36-
37-
Some algorithms have known hash collision weaknesses, refer to the "See
38-
also" section at the end.
39-
4036

4137
.. _hash-algorithms:
4238

4339
Hash algorithms
4440
---------------
4541

4642
There is one constructor method named for each type of :dfn:`hash`. All return
47-
a hash object with the same simple interface. For example: use :func:`sha256` to
48-
create a SHA-256 hash object. You can now feed this object with :term:`bytes-like
49-
objects <bytes-like object>` (normally :class:`bytes`) using the :meth:`update` method.
50-
At any point you can ask it for the :dfn:`digest` of the
51-
concatenation of the data fed to it so far using the :meth:`digest` or
52-
:meth:`hexdigest` methods.
53-
54-
.. note::
55-
56-
For better multithreading performance, the Python :term:`GIL` is released for
57-
data larger than 2047 bytes at object creation or on update.
43+
a hash object with the same simple interface. For example: use :func:`sha256`
44+
to create a SHA-256 hash object. You can now feed this object with
45+
:term:`bytes-like objects <bytes-like object>` (normally :class:`bytes`) using
46+
the :meth:`update<hash.update>` method. At any point you can ask it for the
47+
:dfn:`digest` of the concatenation of the data fed to it so far using the
48+
:meth:`digest()<hash.digest>` or :meth:`hexdigest()<hash.hexdigest>` methods.
5849

59-
.. note::
50+
To allow multithreading, the Python :term:`GIL` is released while computing a
51+
hash supplied more than 2047 bytes of data at once in its constructor or
52+
:meth:`.update<hash.update>` method.
6053

61-
Feeding string objects into :meth:`update` is not supported, as hashes work
62-
on bytes, not on characters.
6354

6455
.. index:: single: OpenSSL; (use in module hashlib)
6556

6657
Constructors for hash algorithms that are always present in this module are
67-
:func:`sha1`, :func:`sha224`, :func:`sha256`, :func:`sha384`,
68-
:func:`sha512`, :func:`blake2b`, and :func:`blake2s`.
69-
:func:`md5` is normally available as well, though it
70-
may be missing or blocked if you are using a rare "FIPS compliant" build of Python.
71-
Additional algorithms may also be available depending upon the OpenSSL
72-
library that Python uses on your platform. On most platforms the
58+
:func:`sha1`, :func:`sha224`, :func:`sha256`, :func:`sha384`, :func:`sha512`,
7359
:func:`sha3_224`, :func:`sha3_256`, :func:`sha3_384`, :func:`sha3_512`,
74-
:func:`shake_128`, :func:`shake_256` are also available.
60+
:func:`shake_128`, :func:`shake_256`, :func:`blake2b`, and :func:`blake2s`.
61+
:func:`md5` is normally available as well, though it may be missing or blocked
62+
if you are using a rare "FIPS compliant" build of Python.
63+
These correspond to :data:`algorithms_guaranteed`.
64+
65+
Additional algorithms may also be available if your Python distribution's
66+
:mod:`hashlib` was linked against a build of OpenSSL that provides others.
67+
Others *are not guaranteed available* on all installations and will only be
68+
accessible by name via :func:`new`. See :data:`algorithms_available`.
69+
70+
.. warning::
71+
72+
Some algorithms have known hash collision weaknesses (including MD5 and
73+
SHA1). Refer to `Attacks on cryptographic hash algorithms`_ and the
74+
`hashlib-seealso`_ section at the end of this document.
7575

7676
.. versionadded:: 3.6
7777
SHA3 (Keccak) and SHAKE constructors :func:`sha3_224`, :func:`sha3_256`,
78-
:func:`sha3_384`, :func:`sha3_512`, :func:`shake_128`, :func:`shake_256`.
78+
:func:`sha3_384`, :func:`sha3_512`, :func:`shake_128`, :func:`shake_256`
79+
were added.
7980

8081
.. versionadded:: 3.6
8182
:func:`blake2b` and :func:`blake2s` were added.
@@ -89,10 +90,19 @@ library that Python uses on your platform. On most platforms the
8990
that the hashing algorithm is not used in a security context, e.g. as a
9091
non-cryptographic one-way compression function.
9192

92-
Hashlib now uses SHA3 and SHAKE from OpenSSL 1.1.1 and newer.
93+
.. versionchanged:: 3.9
94+
Hashlib now uses SHA3 and SHAKE from OpenSSL if it provides it.
95+
96+
.. versionchanged:: 3.12
97+
For any of the MD5, SHA1, SHA2, or SHA3 algorithms that the linked
98+
OpenSSL does not provide we fall back to a verified implementation from
99+
the `HACL\* project`_.
100+
101+
Usage
102+
-----
93103

94-
For example, to obtain the digest of the byte string ``b"Nobody inspects the
95-
spammish repetition"``::
104+
To obtain the digest of the byte string ``b"Nobody inspects the spammish
105+
repetition"``::
96106

97107
>>> import hashlib
98108
>>> m = hashlib.sha256()
@@ -108,22 +118,42 @@ More condensed:
108118
>>> hashlib.sha256(b"Nobody inspects the spammish repetition").hexdigest()
109119
'031edd7d41651593c5fe5c006fa5752b37fddff7bc4e843aa6af0c950f4b9406'
110120

111-
.. function:: new(name[, data], *, usedforsecurity=True)
121+
Constructors
122+
------------
123+
124+
.. function:: new(name[, data], \*, usedforsecurity=True)
112125

113126
Is a generic constructor that takes the string *name* of the desired
114127
algorithm as its first parameter. It also exists to allow access to the
115128
above listed hashes as well as any other algorithms that your OpenSSL
116-
library may offer. The named constructors are much faster than :func:`new`
117-
and should be preferred.
129+
library may offer.
118130

119-
Using :func:`new` with an algorithm provided by OpenSSL:
131+
Using :func:`new` with an algorithm name:
120132

121133
>>> h = hashlib.new('sha256')
122134
>>> h.update(b"Nobody inspects the spammish repetition")
123135
>>> h.hexdigest()
124136
'031edd7d41651593c5fe5c006fa5752b37fddff7bc4e843aa6af0c950f4b9406'
125137

126-
Hashlib provides the following constant attributes:
138+
139+
.. function:: md5([, data], \*, usedforsecurity=True)
140+
.. function:: sha1([, data], \*, usedforsecurity=True)
141+
.. function:: sha224([, data], \*, usedforsecurity=True)
142+
.. function:: sha256([, data], \*, usedforsecurity=True)
143+
.. function:: sha384([, data], \*, usedforsecurity=True)
144+
.. function:: sha512([, data], \*, usedforsecurity=True)
145+
.. function:: sha3_224([, data], \*, usedforsecurity=True)
146+
.. function:: sha3_256([, data], \*, usedforsecurity=True)
147+
.. function:: sha3_384([, data], \*, usedforsecurity=True)
148+
.. function:: sha3_512([, data], \*, usedforsecurity=True)
149+
150+
Named constructors such as these are faster than passing an algorithm name to
151+
:func:`new`.
152+
153+
Attributes
154+
----------
155+
156+
Hashlib provides the following constant module attributes:
127157

128158
.. data:: algorithms_guaranteed
129159

@@ -144,10 +174,12 @@ Hashlib provides the following constant attributes:
144174

145175
.. versionadded:: 3.2
146176

177+
Hash Objects
178+
------------
179+
147180
The following values are provided as constant attributes of the hash objects
148181
returned by the constructors:
149182

150-
151183
.. data:: hash.digest_size
152184

153185
The size of the resulting hash in bytes.
@@ -178,11 +210,6 @@ A hash object has the following methods:
178210
concatenation of all the arguments: ``m.update(a); m.update(b)`` is
179211
equivalent to ``m.update(a+b)``.
180212

181-
.. versionchanged:: 3.1
182-
The Python GIL is released to allow other threads to run while hash
183-
updates on data larger than 2047 bytes is taking place when using hash
184-
algorithms supplied by OpenSSL.
185-
186213

187214
.. method:: hash.digest()
188215

@@ -207,6 +234,9 @@ A hash object has the following methods:
207234
SHAKE variable length digests
208235
-----------------------------
209236

237+
.. function:: shake_128([, data], \*, usedforsecurity=True)
238+
.. function:: shake_256([, data], \*, usedforsecurity=True)
239+
210240
The :func:`shake_128` and :func:`shake_256` algorithms provide variable
211241
length digests with length_in_bits//2 up to 128 or 256 bits of security.
212242
As such, their digest methods require a length. Maximum length is not limited
@@ -223,8 +253,13 @@ by the SHAKE algorithm.
223253

224254
Like :meth:`digest` except the digest is returned as a string object of
225255
double length, containing only hexadecimal digits. This may be used to
226-
exchange the value safely in email or other non-binary environments.
256+
exchange the value in email or other non-binary environments.
227257

258+
Example use:
259+
260+
>>> h = hashlib.shake_256(b'Nobody inspects the spammish repetition')
261+
>>> h.hexdigest(20)
262+
'44709d6fcb83d92a76dcb0b668c98e1b1d3dafe7'
228263

229264
File hashing
230265
------------
@@ -768,12 +803,18 @@ Domain Dedication 1.0 Universal:
768803
.. _BLAKE2: https://www.blake2.net
769804
.. _HMAC: https://en.wikipedia.org/wiki/Hash-based_message_authentication_code
770805
.. _BLAKE: https://web.archive.org/web/20200918190133/https://131002.net/blake/
771-
.. _SHA-3: https://en.wikipedia.org/wiki/NIST_hash_function_competition
806+
.. _SHA-3: https://en.wikipedia.org/wiki/Secure_Hash_Algorithms
772807
.. _ChaCha: https://cr.yp.to/chacha.html
773808
.. _pyblake2: https://pythonhosted.org/pyblake2/
774809
.. _NIST-SP-800-132: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf
775810
.. _stackexchange pbkdf2 iterations question: https://security.stackexchange.com/questions/3959/recommended-of-iterations-when-using-pbkdf2-sha256/
811+
.. _Attacks on cryptographic hash algorithms: https://en.wikipedia.org/wiki/Cryptographic_hash_function#Attacks_on_cryptographic_hash_algorithms
812+
.. _the FIPS 180-4 standard: https://csrc.nist.gov/publications/detail/fips/180/4/final
813+
.. _the FIPS 202 standard: https://csrc.nist.gov/publications/detail/fips/202/final
814+
.. _HACL\* project: https://github.com/hacl-star/hacl-star
815+
776816

817+
.. _hashlib-seealso:
777818

778819
.. seealso::
779820

@@ -783,15 +824,18 @@ Domain Dedication 1.0 Universal:
783824
Module :mod:`base64`
784825
Another way to encode binary hashes for non-binary environments.
785826

786-
https://www.blake2.net
787-
Official BLAKE2 website.
827+
https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.180-4.pdf
828+
The FIPS 180-4 publication on Secure Hash Algorithms.
829+
830+
https://csrc.nist.gov/publications/detail/fips/202/final
831+
The FIPS 202 publication on the SHA-3 Standard.
788832

789-
https://csrc.nist.gov/csrc/media/publications/fips/180/2/archive/2002-08-01/documents/fips180-2.pdf
790-
The FIPS 180-2 publication on Secure Hash Algorithms.
833+
https://www.blake2.net/
834+
Official BLAKE2 website.
791835

792-
https://en.wikipedia.org/wiki/Cryptographic_hash_function#Cryptographic_hash_algorithms
793-
Wikipedia article with information on which algorithms have known issues and
794-
what that means regarding their use.
836+
https://en.wikipedia.org/wiki/Cryptographic_hash_function
837+
Wikipedia article with information on which algorithms have known issues
838+
and what that means regarding their use.
795839

796840
https://www.ietf.org/rfc/rfc8018.txt
797841
PKCS #5: Password-Based Cryptography Specification Version 2.1

0 commit comments

Comments
 (0)