Skip to content

Commit 6a3c69d

Browse files
authored
Merge branch 'main' into fix-cmath-log-zero-base
2 parents f65bff8 + b968417 commit 6a3c69d

20 files changed

Lines changed: 127 additions & 12 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/whatsnew/3.16.rst‎

Lines changed: 29 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

@@ -1408,6 +1415,28 @@ that may require changes to your code.
14081415
:exc:`TypeError`.
14091416
(Contributed by Serhiy Storchaka in :gh:`152587`.)
14101417

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,7 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
16081608
path.
16091609
16101610
"""
1611+
cmd = os.fspath(cmd)
16111612
use_bytes = isinstance(cmd, bytes)
16121613

16131614
# If we're given a path with a directory part, look it up directly rather

‎Lib/test/test_augassign.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@ def testSequences(self):
6464
self.assertEqual(x, [1, 2, 1, 2, 3])
6565
self.assertTrue(x is y)
6666

67+
def testSequenceRepeatRightOperand(self):
68+
# gh-161968
69+
class MyInt(int):
70+
pass
71+
class Index:
72+
def __index__(self):
73+
return 2
74+
75+
seq = [1]
76+
x = MyInt(2)
77+
x *= seq
78+
self.assertEqual(x, [1, 1])
79+
# The right operand is not modified in place.
80+
self.assertEqual(seq, [1])
81+
82+
x = Index()
83+
x *= 'a'
84+
self.assertEqual(x, 'aa')
85+
6786
def testCustomMethods1(self):
6887

6988
class aug_test:

‎Lib/test/test_httplib.py‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def append(self, item):
200200
# Here, we're testing that methods expecting a body get a
201201
# content-length set to zero if the body is empty (either None or '')
202202
bodies = (None, '')
203-
methods_with_body = ('PUT', 'POST', 'PATCH')
203+
methods_with_body = ('PUT', 'POST', 'PATCH', 'QUERY')
204204
for method, body in itertools.product(methods_with_body, bodies):
205205
conn = client.HTTPConnection('example.com')
206206
conn.sock = FakeSocket(None)
@@ -554,6 +554,34 @@ def test_invalid_method_names(self):
554554
conn.sock = FakeSocket(None)
555555
conn.request(method=method, url="/")
556556

557+
def test_query_request(self):
558+
# QUERY (RFC 10008) is sent with a body, like PUT/POST/PATCH.
559+
conn = client.HTTPConnection('example.com')
560+
conn.sock = FakeSocket(None)
561+
conn.request('QUERY', '/contacts', body='name=python',
562+
headers={'Content-Type': 'application/x-www-form-urlencoded'})
563+
self.assertEqual(conn.sock.data,
564+
b'QUERY /contacts HTTP/1.1\r\n'
565+
b'Host: example.com\r\n'
566+
b'Accept-Encoding: identity\r\n'
567+
b'Content-Length: 11\r\n'
568+
b'Content-Type: application/x-www-form-urlencoded\r\n'
569+
b'\r\n'
570+
b'name=python')
571+
572+
def test_query_request_no_body(self):
573+
# A QUERY without a body still gets Content-Length: 0, since some
574+
# servers respond with 411 otherwise.
575+
conn = client.HTTPConnection('example.com')
576+
conn.sock = FakeSocket(None)
577+
conn.request('QUERY', '/contacts')
578+
self.assertEqual(conn.sock.data,
579+
b'QUERY /contacts HTTP/1.1\r\n'
580+
b'Host: example.com\r\n'
581+
b'Accept-Encoding: identity\r\n'
582+
b'Content-Length: 0\r\n'
583+
b'\r\n')
584+
557585

558586
class TransferEncodingTest(TestCase):
559587
expected_body = b"It's just a flesh wound"

‎Lib/test/test_set.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,17 @@ def test_constructor_identity(self):
762762
t = self.thetype(s)
763763
self.assertEqual(id(s), id(t))
764764

765+
def test_gc_tracking(self):
766+
# gh-140232: frozensets whose elements can never be tracked by the
767+
# GC are not tracked, including the compiled frozenset({...}) form
768+
s = {1, 2}
769+
self.assertFalse(gc.is_tracked(frozenset(s)))
770+
self.assertFalse(gc.is_tracked(frozenset({1, 2})))
771+
self.assertFalse(gc.is_tracked(frozenset({x for x in range(2)})))
772+
class C:
773+
pass
774+
self.assertTrue(gc.is_tracked(frozenset({C()})))
775+
765776
def test_hash(self):
766777
self.assertEqual(hash(self.thetype('abcdeb')),
767778
hash(self.thetype('ebecda')))

0 commit comments

Comments
 (0)