Skip to content

Commit 5aefbe4

Browse files
authored
Merge branch 'main' into email-utils-doc-param-names
2 parents 8654c01 + 369d8bc commit 5aefbe4

37 files changed

Lines changed: 437 additions & 43 deletions

‎Doc/library/http.client.rst‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ HTTPConnection Objects
312312
but there is a request body, one of those
313313
header fields will be added automatically. If
314314
*body* is ``None``, the Content-Length header is set to ``0`` for
315-
methods that expect a body (``PUT``, ``POST``, and ``PATCH``). If
315+
methods that expect a body (``PUT``, ``POST``, ``PATCH``, and ``QUERY``). If
316316
*body* is a string or a bytes-like object that is not also a
317317
:term:`file <file object>`, the Content-Length header is
318318
set to its length. Any other type of *body* (files
@@ -369,6 +369,9 @@ HTTPConnection Objects
369369
*continue_timeout* value must be greater than zero, otherwise
370370
:exc:`ValueError` is raised.
371371

372+
.. versionchanged:: next
373+
``QUERY`` was added to the methods that expect a body.
374+
372375
.. method:: HTTPConnection.getresponse(support_continue=False)
373376

374377
Should be called after a request is sent to get the response from the server.

‎Doc/library/http.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ Property Indicates that Details
194194
<HTTPMethod.PATCH>,
195195
<HTTPMethod.POST>,
196196
<HTTPMethod.PUT>,
197+
<HTTPMethod.QUERY>,
197198
<HTTPMethod.TRACE>]
198199

199200
.. _http-methods:
@@ -217,4 +218,5 @@ Method Enum Name Details
217218
``OPTIONS`` ``OPTIONS`` HTTP Semantics :rfc:`9110`, Section 9.3.7
218219
``TRACE`` ``TRACE`` HTTP Semantics :rfc:`9110`, Section 9.3.8
219220
``PATCH`` ``PATCH`` HTTP/1.1 :rfc:`5789`
221+
``QUERY`` ``QUERY`` The HTTP QUERY Method :rfc:`10008`
220222
=========== =================================== ==================================================================

‎Doc/library/ipaddress.rst‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ dictionaries.
739739
Traceback (most recent call last):
740740
File "<stdin>", line 1, in <module>
741741
raise ValueError(
742-
ValueError: next prefix must be between 1 and 32
742+
ValueError: prefix must be between 1 and 32
743743
>>> IPv4Network('255.255.255.0/24').next_network()
744744
Traceback (most recent call last):
745745
File "<stdin>", line 1, in <module>
@@ -748,6 +748,36 @@ dictionaries.
748748

749749
.. versionadded:: 3.16
750750

751+
.. method:: prev_network(prev_prefix=None)
752+
753+
Finds the previous closest network of prefix size *prev_prefix*. If
754+
*prev_prefix=None*, then the current network prefix will be used.
755+
Returns a single network object.
756+
757+
Raises :exc:`ValueError` if *prev_prefix* is out of range or no further
758+
network of the requested size exists.
759+
760+
>>> IPv4Network('192.0.2.0/24').prev_network()
761+
IPv4Network('192.0.1.0/24')
762+
>>> IPv4Network('192.0.2.0/24').prev_network(prev_prefix=25)
763+
IPv4Network('192.0.1.128/25')
764+
>>> IPv4Network('192.0.2.0/24').prev_network(prev_prefix=23)
765+
IPv4Network('192.0.0.0/23')
766+
>>> IPv4Network('192.0.80.0/22').prev_network(prev_prefix=18)
767+
IPv4Network('192.0.0.0/18')
768+
>>> IPv4Network('192.0.80.0/22').prev_network(prev_prefix=50)
769+
Traceback (most recent call last):
770+
File "<stdin>", line 1, in <module>
771+
raise ValueError(
772+
ValueError: prefix must be between 1 and 32
773+
>>> IPv4Network('0.0.0.0/24').prev_network()
774+
Traceback (most recent call last):
775+
File "<stdin>", line 1, in <module>
776+
raise ValueError(
777+
ValueError: out of address space, cannot make another /24 network
778+
779+
.. versionadded:: 3.16
780+
751781
.. class:: IPv6Network(address, strict=True)
752782

753783
Construct an IPv6 network definition. *address* can be one of the following:
@@ -820,6 +850,7 @@ dictionaries.
820850
.. method:: subnet_of(other)
821851
.. method:: supernet_of(other)
822852
.. method:: next_network(next_prefix=None)
853+
.. method:: prev_network(prev_prefix=None)
823854
.. method:: compare_networks(other)
824855

825856
Refer to the corresponding attribute documentation in

‎Doc/library/shutil.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@ Directory and files operations
532532
or ends with an extension that is in ``PATHEXT``; and filenames that
533533
have no extension can now be found.
534534

535+
.. versionchanged:: next
536+
Accepts a :term:`path-like object` for *cmd*.
537+
535538
.. exception:: Error
536539

537540
Subclass of :exc:`OSError` collecting exceptions raised during a multi-file

‎Doc/whatsnew/3.15.rst‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,6 +2526,17 @@ New features
25262526

25272527
(Contributed by Victor Stinner in :gh:`141510`.)
25282528

2529+
* Add the :pep:`757` export/import functions to the limited C API:
2530+
2531+
* :c:func:`PyLong_GetNativeLayout`
2532+
* :c:func:`PyLong_Export`
2533+
* :c:func:`PyLong_FreeExport`
2534+
* :c:func:`PyLongWriter_Create`
2535+
* :c:func:`PyLongWriter_Finish`
2536+
* :c:func:`PyLongWriter_Discard`
2537+
2538+
(Contributed by Sergey B Kirpichev in :gh:`143869`.)
2539+
25292540
* Add :c:func:`PyObject_CallFinalizerFromDealloc` function to the limited C
25302541
API.
25312542
(Contributed by Victor Stinner in :gh:`146063`.)

‎Doc/whatsnew/3.16.rst‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,13 @@ gzip
508508
(Contributed by Marin Misur in :gh:`91372`.)
509509

510510

511+
http
512+
----
513+
514+
* Add the ``QUERY`` HTTP method (:rfc:`10008`) to :class:`~http.HTTPMethod`.
515+
(Contributed by Michiel W. Beijen in :gh:`153309`.)
516+
517+
511518
http.client
512519
-----------
513520

@@ -594,6 +601,10 @@ ipaddress
594601
and :meth:`IPv6Network.next_network() <ipaddress.IPv6Network.next_network>`
595602
methods to find the next nearest network with a specific prefix size.
596603
(Contributed by Faisal Mahmood in :gh:`87027`.)
604+
* Add :meth:`IPv4Network.prev_network() <ipaddress.IPv4Network.prev_network>`
605+
and :meth:`IPv6Network.prev_network() <ipaddress.IPv6Network.prev_network>`
606+
methods to find the previous nearest network with a specific prefix size.
607+
(Contributed by Faisal Mahmood in :gh:`87027`.)
597608

598609

599610
logging
@@ -1408,6 +1419,28 @@ that may require changes to your code.
14081419
:exc:`TypeError`.
14091420
(Contributed by Serhiy Storchaka in :gh:`152587`.)
14101421

1422+
* :func:`urllib.parse.urlsplit` and :func:`urllib.parse.urlparse` now raise
1423+
:exc:`ValueError` when the URL is parsed if the port is not a decimal
1424+
number or is outside the range 0--65535. Previously, the error was only
1425+
raised when the :attr:`!port` attribute was read. This also affects
1426+
:func:`~urllib.parse.urljoin`, and :func:`~urllib.parse.urldefrag` for
1427+
URLs with a fragment. Code which never read :attr:`!port` may now fail
1428+
on URLs such as:
1429+
1430+
* SCP-style addresses given a scheme, such as
1431+
``git+ssh://git@github.com:org/repo.git``;
1432+
* multi-host URLs with ports, such as
1433+
``mongodb://h1:27017,h2:27017/db`` or
1434+
``postgresql://h1:5432,h2:5433/db``;
1435+
* URL templates with a placeholder port, such as
1436+
``http://localhost:{port}/``.
1437+
1438+
These are not valid URLs under :rfc:`3986`. To process them, split off
1439+
the netloc yourself before calling :func:`~urllib.parse.urlsplit`, for
1440+
example by replacing it with a placeholder host, or fill in templates
1441+
before parsing them.
1442+
(Contributed by Miguel Brito and Senthil Kumaran in :gh:`88037`.)
1443+
14111444
* :class:`uuid.UUID` now consistently raises :exc:`TypeError` when the
14121445
*bytes* or *bytes_le* argument is not a :class:`bytes` object.
14131446
Previously, some invalid inputs raised :exc:`AssertionError` or

‎Include/internal/pycore_instruction_sequence.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ typedef struct instruction_sequence {
4040
/* Map of a label id to instruction offset (index into s_instrs).
4141
* If s_labelmap is NULL, then each label id is the offset itself.
4242
*/
43-
int *s_labelmap;
4443
int s_labelmap_size;
44+
int *s_labelmap;
4545

4646
/* PyList of instruction sequences of nested functions */
4747
PyObject *s_nested;

‎Lib/http/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class HTTPMethod:
192192
193193
* RFC 9110: HTTP Semantics, obsoletes 7231, which obsoleted 2616
194194
* RFC 5789: PATCH Method for HTTP
195+
* RFC 10008: The HTTP QUERY Method
195196
"""
196197
def __new__(cls, value, description):
197198
obj = str.__new__(cls, value)
@@ -210,4 +211,5 @@ def __repr__(self):
210211
PATCH = 'PATCH', 'Apply partial modifications to a target.'
211212
POST = 'POST', 'Perform target-specific processing with the request payload.'
212213
PUT = 'PUT', 'Replace the target with the request payload.'
214+
QUERY = 'QUERY', 'Request that the target process the request payload in a safe and idempotent manner.'
213215
TRACE = 'TRACE', 'Perform a message loop-back test along the path to the target.'

‎Lib/http/client.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183

184184
# We always set the Content-Length header for these methods because some
185185
# servers will otherwise respond with a 411
186-
_METHODS_EXPECTING_BODY = {'PATCH', 'POST', 'PUT'}
186+
_METHODS_EXPECTING_BODY = {'PATCH', 'POST', 'PUT', 'QUERY'}
187187

188188

189189
def _encode(data, name='data'):

‎Lib/ipaddress.py‎

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,46 @@ def is_loopback(self):
11191119
return (self.network_address.is_loopback and
11201120
self.broadcast_address.is_loopback)
11211121

1122+
def _network_by_offset(self, prefix, offset):
1123+
"""Get the network offset from this network.
1124+
1125+
Args:
1126+
prefix: Target prefix length.
1127+
offset: Number of networks to move (+1 or -1).
1128+
1129+
Returns:
1130+
An IPv(4|6) Network object.
1131+
1132+
"""
1133+
if prefix < 1 or prefix > self.max_prefixlen:
1134+
raise ValueError(
1135+
f"prefix must be between 1 and {self.max_prefixlen}"
1136+
)
1137+
new_netmask, _ = self._make_netmask(prefix)
1138+
error = f"out of address space, cannot make another /{prefix} network"
1139+
1140+
if prefix > self.prefixlen:
1141+
if offset < 0:
1142+
new_ip = self.network_address._ip - 1
1143+
else:
1144+
new_ip = self.broadcast_address._ip + 1
1145+
if new_ip < 0 or new_ip > self._ALL_ONES:
1146+
raise ValueError(error)
1147+
1148+
new_ip &= new_netmask._ip
1149+
else:
1150+
bit_shift = self.max_prefixlen - prefix
1151+
new_ip = (
1152+
((new_netmask._ip & self.network_address._ip) >> bit_shift)
1153+
+ offset
1154+
) << bit_shift
1155+
if not 0 <= new_ip <= self._ALL_ONES:
1156+
raise ValueError(error)
1157+
1158+
return self.__class__(
1159+
f"{self._string_from_ip_int(new_ip)}/{prefix}"
1160+
)
1161+
11221162
def next_network(self, next_prefix=None):
11231163
"""Get the next closest network with a specific prefix.
11241164
@@ -1136,31 +1176,25 @@ def next_network(self, next_prefix=None):
11361176
"""
11371177
if next_prefix is None:
11381178
next_prefix = self.prefixlen
1139-
new_netmask = self.netmask
1140-
else:
1141-
if next_prefix < 1 or next_prefix > self.max_prefixlen:
1142-
raise ValueError(
1143-
f"next prefix must be between 1 and {self.max_prefixlen}"
1144-
)
1145-
new_netmask, _ = self._make_netmask(next_prefix)
11461179

1147-
bit_shift = (
1148-
self.max_prefixlen - next_prefix
1149-
if next_prefix <= self.prefixlen
1150-
else self.max_prefixlen - self.prefixlen
1151-
)
1180+
return self._network_by_offset(next_prefix, 1)
11521181

1153-
next_ip = (
1154-
((new_netmask._ip & self.network_address._ip) >> bit_shift) + 1
1155-
) << bit_shift
11561182

1157-
if next_ip > self._ALL_ONES:
1158-
raise ValueError(
1159-
f"out of address space, cannot make another /{next_prefix} "
1160-
"network"
1161-
)
1183+
def prev_network(self, prev_prefix=None):
1184+
"""Get the previous closest network with a specific prefix.
1185+
1186+
Args:
1187+
prev_prefix: The desired previous prefix length, if not specified the
1188+
same self.prefixlen will be used
1189+
1190+
Returns:
1191+
An IPv(4|6) Network object of the previous closest network.
1192+
1193+
"""
1194+
if prev_prefix is None:
1195+
prev_prefix = self.prefixlen
11621196

1163-
return self.__class__((next_ip, next_prefix))
1197+
return self._network_by_offset(prev_prefix, -1)
11641198

11651199

11661200
class _BaseConstants:

0 commit comments

Comments
 (0)