]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-101936: Update the default value of fp from io.StringIO to io.BytesIO ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 22 Feb 2023 11:42:04 +0000 (03:42 -0800)
committerGitHub <noreply@github.com>
Wed, 22 Feb 2023 11:42:04 +0000 (20:42 +0900)
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 <long.vo@linecorp.com>
Lib/test/test_urllib2.py
Lib/urllib/error.py
Misc/ACKS
Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst [new file with mode: 0644]

index db92ba56c34f80c56392c0f165a2a7b936725127..230b937645b53bbdbe9efeecb39942a8f4cec946 100644 (file)
@@ -1828,6 +1828,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 = [
index feec0e7f848e463ed22f03785373ed90f3aff561..a9cd1ecadd63f2b09ee4363fc283e8f1f5cbbb3b 100644 (file)
@@ -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):
index cf6657f9559a670df07f0fcacff3f476246b9af4..95e0589076c6354fa7137d50a384555907266a17 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1882,6 +1882,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 (file)
index 0000000..55841da
--- /dev/null
@@ -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.