From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 22 Feb 2023 11:42:28 +0000 (-0800) Subject: [3.10] gh-101936: Update the default value of fp from io.StringIO to io.BytesIO ... X-Git-Tag: v3.10.11~88 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0f28af589bd23a1daceedfe03d920a619b03cb6c;p=thirdparty%2FPython%2Fcpython.git [3.10] gh-101936: Update the default value of fp from io.StringIO to io.BytesIO (gh-102100) (#102118) gh-101936: Update the default value of fp from io.StringIO to io.BytesIO (gh-102100) (cherry picked from commit 0d4c7fcd4f078708a5ac6499af378ce5ee8eb211) Co-authored-by: Long Vo --- diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 4ef391c4540c..55f45db7288b 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1826,6 +1826,7 @@ class MiscTests(unittest.TestCase): def test_gh_98778(self): x = urllib.error.HTTPError("url", 405, "METHOD NOT ALLOWED", None, None) self.assertEqual(getattr(x, "__notes__", ()), ()) + self.assertIsInstance(x.fp.read(), bytes) def test_parse_proxy(self): parse_proxy_test_cases = [ diff --git a/Lib/urllib/error.py b/Lib/urllib/error.py index feec0e7f848e..a9cd1ecadd63 100644 --- a/Lib/urllib/error.py +++ b/Lib/urllib/error.py @@ -43,7 +43,7 @@ class HTTPError(URLError, urllib.response.addinfourl): self.fp = fp self.filename = url if fp is None: - fp = io.StringIO() + fp = io.BytesIO() self.__super_init(fp, hdrs, url, code) def __str__(self): diff --git a/Misc/ACKS b/Misc/ACKS index c96c4876e6cb..10a35fd64abf 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1867,6 +1867,7 @@ Kurt Vile Norman Vine Pauli Virtanen Frank Visser +Long Vo Johannes Vogel Michael Vogt Radu Voicilas diff --git a/Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst b/Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst new file mode 100644 index 000000000000..55841da44b11 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst @@ -0,0 +1,2 @@ +The default value of ``fp`` becomes :class:`io.BytesIO` if :exc:`~urllib.error.HTTPError` +is initialized without a designated ``fp`` parameter. Patch by Long Vo.