Skip to content

Commit

Permalink
pythongh-101936: Update the default value of fp from io.StringIO to i…
Browse files Browse the repository at this point in the history
…o.BytesIO (pythongh-102100)

(cherry picked from commit 0d4c7fc)

Co-authored-by: Vo Hoang Long <vohoanglong07@gmail.com>
Co-authored-by: Long Vo <long.vo@linecorp.com>
  • Loading branch information
2 people authored and miss-islington committed Feb 21, 2023
1 parent 444ec74 commit 496a500
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions Lib/test/test_urllib2.py
Expand Up @@ -1826,6 +1826,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.assertIsInstance(x.fp.read(), bytes)

def test_parse_proxy(self):
parse_proxy_test_cases = [
Expand Down
2 changes: 1 addition & 1 deletion Lib/urllib/error.py
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Expand Up @@ -1866,6 +1866,7 @@ Kurt Vile
Norman Vine
Pauli Virtanen
Frank Visser
Long Vo
Johannes Vogel
Michael Vogt
Radu Voicilas
Expand Down
@@ -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.

0 comments on commit 496a500

Please sign in to comment.