Skip to content

Commit f015cd2

Browse files
committed
Branch merge
2 parents 80a91b2 + 5930725 commit f015cd2

9 files changed

Lines changed: 43 additions & 13 deletions

File tree

Doc/library/http.client.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,10 @@ also send your request step by step, by using the four functions below.
475475
.. method:: HTTPConnection.endheaders(message_body=None)
476476

477477
Send a blank line to the server, signalling the end of the headers. The
478-
optional message_body argument can be used to pass message body
479-
associated with the request. The message body will be sent in
480-
the same packet as the message headers if possible. The
481-
message_body should be a string.
482-
478+
optional *message_body* argument can be used to pass a message body
479+
associated with the request. The message body will be sent in the same
480+
packet as the message headers if it is string, otherwise it is sent in a
481+
separate packet.
483482

484483
.. method:: HTTPConnection.send(data)
485484

Lib/http/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -947,11 +947,11 @@ def putheader(self, header, *values):
947947
def endheaders(self, message_body=None):
948948
"""Indicate that the last header line has been sent to the server.
949949
950-
This method sends the request to the server. The optional
951-
message_body argument can be used to pass message body
952-
associated with the request. The message body will be sent in
953-
the same packet as the message headers if possible. The
954-
message_body should be a string.
950+
This method sends the request to the server. The optional message_body
951+
argument can be used to pass a message body associated with the
952+
request. The message body will be sent in the same packet as the
953+
message headers if it is a string, otherwise it is sent as a separate
954+
packet.
955955
"""
956956
if self.__state == _CS_REQ_STARTED:
957957
self.__state = _CS_REQ_SENT

Lib/test/test_import.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from importlib.test.import_ import util as importlib_util
55
import marshal
66
import os
7+
import platform
78
import py_compile
89
import random
910
import stat
@@ -546,6 +547,8 @@ def test_import_pyc_path(self):
546547

547548
@unittest.skipUnless(os.name == 'posix',
548549
"test meaningful only on posix systems")
550+
@unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
551+
"due to varying filesystem permission semantics (issue #11956)")
549552
def test_unwritable_directory(self):
550553
# When the umask causes the new __pycache__ directory to be
551554
# unwritable, the import still succeeds but no .pyc file is written.

Lib/test/test_io.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,21 @@ def test_garbage_collection(self):
24142414
with self.open(support.TESTFN, "rb") as f:
24152415
self.assertEqual(f.read(), b"456def")
24162416

2417+
def test_rwpair_cleared_before_textio(self):
2418+
# Issue 13070: TextIOWrapper's finalization would crash when called
2419+
# after the reference to the underlying BufferedRWPair's writer got
2420+
# cleared by the GC.
2421+
for i in range(1000):
2422+
b1 = self.BufferedRWPair(self.MockRawIO(), self.MockRawIO())
2423+
t1 = self.TextIOWrapper(b1, encoding="ascii")
2424+
b2 = self.BufferedRWPair(self.MockRawIO(), self.MockRawIO())
2425+
t2 = self.TextIOWrapper(b2, encoding="ascii")
2426+
# circular references
2427+
t1.buddy = t2
2428+
t2.buddy = t1
2429+
support.gc_collect()
2430+
2431+
24172432
class PyTextIOWrapperTest(TextIOWrapperTest):
24182433
pass
24192434

Lib/test/test_sys_settrace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,11 @@ def run_test2(self, func):
282282
self.compare_events(func.__code__.co_firstlineno,
283283
tracer.events, func.events)
284284

285-
def set_and_retrieve_none(self):
285+
def test_set_and_retrieve_none(self):
286286
sys.settrace(None)
287287
assert sys.gettrace() is None
288288

289-
def set_and_retrieve_func(self):
289+
def test_set_and_retrieve_func(self):
290290
def fn(*args):
291291
pass
292292

Lib/test/test_urllib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,10 @@ def test_splitpasswd(self):
10581058
self.assertEqual(('user', 'a\vb'),urllib.parse.splitpasswd('user:a\vb'))
10591059
self.assertEqual(('user', 'a:b'),urllib.parse.splitpasswd('user:a:b'))
10601060

1061+
def test_thishost(self):
1062+
"""Test the urllib.request.thishost utility function returns a tuple"""
1063+
self.assertIsInstance(urllib.request.thishost(), tuple)
1064+
10611065

10621066
class URLopener_Tests(unittest.TestCase):
10631067
"""Testcase to test the open method of URLopener class."""

Lib/urllib/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ def thishost():
21162116
"""Return the IP addresses of the current host."""
21172117
global _thishost
21182118
if _thishost is None:
2119-
_thishost = tuple(socket.gethostbyname_ex(socket.gethostname()[2]))
2119+
_thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2])
21202120
return _thishost
21212121

21222122
_ftperrors = None

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ Tests
9898
Extension Modules
9999
-----------------
100100

101+
- Issue #13070: Fix a crash when a TextIOWrapper caught in a reference cycle
102+
would be finalized after the reference to its underlying BufferedRWPair's
103+
writer got cleared by the GC.
104+
101105
- Issue #12881: ctypes: Fix segfault with large structure field names.
102106

103107
- Issue #13058: ossaudiodev: fix a file descriptor leak on error. Patch by

Modules/_io/bufferedio.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,11 @@ bufferedrwpair_isatty(rwpair *self, PyObject *args)
22122212
static PyObject *
22132213
bufferedrwpair_closed_get(rwpair *self, void *context)
22142214
{
2215+
if (self->writer == NULL) {
2216+
PyErr_SetString(PyExc_RuntimeError,
2217+
"the BufferedRWPair object is being garbage-collected");
2218+
return NULL;
2219+
}
22152220
return PyObject_GetAttr((PyObject *) self->writer, _PyIO_str_closed);
22162221
}
22172222

0 commit comments

Comments
 (0)