]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-101936: Update the default value of fp from io.StringIO to io.BytesIO (gh-102100)
authorVo Hoang Long <vohoanglong07@gmail.com>
Tue, 21 Feb 2023 15:14:41 +0000 (22:14 +0700)
committerGitHub <noreply@github.com>
Tue, 21 Feb 2023 15:14:41 +0000 (00:14 +0900)
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 498c0382d2137bc84edf93e4240e8e179cc80a69..633d596ac3de3fe8f5ef9192148ee23e9785a213 100644 (file)
@@ -1827,6 +1827,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 a9d4e453c7b59c77229f34530f1bde4c5d75287d..ab19d69b0133d2110a448a13d2563564e4422e68 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1898,6 +1898,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.