From 5042916982a46215919ba40054c40eb1f038daae Mon Sep 17 00:00:00 2001 From: Long Vo Date: Tue, 21 Feb 2023 07:21:15 +0000 Subject: [PATCH 1/7] HTTPError fp.read returns string instead of bytes --- Lib/urllib/error.py | 2 +- Misc/ACKS | 1 + .../next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst diff --git a/Lib/urllib/error.py b/Lib/urllib/error.py index feec0e7f848e46..a9cd1ecadd63f2 100644 --- a/Lib/urllib/error.py +++ b/Lib/urllib/error.py @@ -43,7 +43,7 @@ def __init__(self, url, code, msg, hdrs, fp): 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 ca92608868f23f..f46ef8aa782c0b 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1897,6 +1897,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 00000000000000..7f9f85b7fff3bc --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst @@ -0,0 +1 @@ +HTTPError fp.read returns string instead of bytes From 35530299d4b9fa8cec46eddd0e7367566a47ae32 Mon Sep 17 00:00:00 2001 From: Long Vo Date: Tue, 21 Feb 2023 10:25:23 +0000 Subject: [PATCH 2/7] update unit test --- Lib/test/test_urllib2.py | 1 + .../Library/2023-02-21-07-48-03.gh-issue-101936.xPawo7.rst | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-02-21-07-48-03.gh-issue-101936.xPawo7.rst diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 498c0382d2137b..9b0c7ba51f9e73 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1827,6 +1827,7 @@ def test_HTTPError_interface(self): def test_gh_98778(self): x = urllib.error.HTTPError("url", 405, "METHOD NOT ALLOWED", None, None) self.assertEqual(getattr(x, "__notes__", ()), ()) + self.assertEqual(isinstance(x.fp.read(), bytes), True) def test_parse_proxy(self): parse_proxy_test_cases = [ diff --git a/Misc/NEWS.d/next/Library/2023-02-21-07-48-03.gh-issue-101936.xPawo7.rst b/Misc/NEWS.d/next/Library/2023-02-21-07-48-03.gh-issue-101936.xPawo7.rst new file mode 100644 index 00000000000000..b6ef6e41d24c1f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-02-21-07-48-03.gh-issue-101936.xPawo7.rst @@ -0,0 +1,3 @@ +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 From 1de16a7742dbc8eb20635e49d49cfb4efd4c4f51 Mon Sep 17 00:00:00 2001 From: Long Vo Date: Tue, 21 Feb 2023 13:41:13 +0000 Subject: [PATCH 3/7] Update Misc/News.d --- .../Library/2023-02-21-07-48-03.gh-issue-101936.xPawo7.rst | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2023-02-21-07-48-03.gh-issue-101936.xPawo7.rst diff --git a/Misc/NEWS.d/next/Library/2023-02-21-07-48-03.gh-issue-101936.xPawo7.rst b/Misc/NEWS.d/next/Library/2023-02-21-07-48-03.gh-issue-101936.xPawo7.rst deleted file mode 100644 index b6ef6e41d24c1f..00000000000000 --- a/Misc/NEWS.d/next/Library/2023-02-21-07-48-03.gh-issue-101936.xPawo7.rst +++ /dev/null @@ -1,3 +0,0 @@ -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 From d5b74b67a71ce59dbd9a0655a389ca2153c7bb01 Mon Sep 17 00:00:00 2001 From: Long Vo Date: Tue, 21 Feb 2023 13:42:53 +0000 Subject: [PATCH 4/7] update unit test --- Lib/test/test_urllib2.py | 2 +- .../next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 9b0c7ba51f9e73..633d596ac3de3f 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -1827,7 +1827,7 @@ def test_HTTPError_interface(self): def test_gh_98778(self): x = urllib.error.HTTPError("url", 405, "METHOD NOT ALLOWED", None, None) self.assertEqual(getattr(x, "__notes__", ()), ()) - self.assertEqual(isinstance(x.fp.read(), bytes), True) + self.assertIsInstance(x.fp.read(), bytes) def test_parse_proxy(self): parse_proxy_test_cases = [ 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 index 7f9f85b7fff3bc..19e40764e20ecb 100644 --- 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 @@ -1 +1 @@ -HTTPError fp.read returns string instead of bytes +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. From b02433e0b0c72c27bd65aeec0e6763a630f93dba Mon Sep 17 00:00:00 2001 From: Long Vo Date: Tue, 21 Feb 2023 13:51:06 +0000 Subject: [PATCH 5/7] Update Misc/NEWS.d --- .../next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 19e40764e20ecb..9ce262f9818721 100644 --- 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 @@ -1 +1 @@ -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. +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. From 9cc16058ccd94daf24dd2fe08d32195b6aa2883a Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Tue, 21 Feb 2023 23:31:20 +0900 Subject: [PATCH 6/7] Update Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst --- .../Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index 9ce262f9818721..f955aa0c23e178 100644 --- 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 @@ -1 +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. +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. From b1c8deaf547d84e5838b9bb3152490e38c916454 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Tue, 21 Feb 2023 23:35:06 +0900 Subject: [PATCH 7/7] Update Misc/NEWS.d/next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst --- .../next/Library/2023-02-21-07-15-41.gh-issue-101936.QVOxHH.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index f955aa0c23e178..55841da44b1146 100644 --- 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 @@ -1,2 +1,2 @@ -The default value of ``fp`` becomes :class:`io.BytesIO` if :exc:`~urllib.error.HTTPError` +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.