| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Since the _TemporaryFileCloser is used for internal usage, this change will not impact to 3rd party libraries. |
Sorry, something went wrong.
(.oss) ➜ cpython git:(gh-98778) ✗ ./python.exe -m test test_urllib2 -R 3:3 Raised RLIMIT_NOFILE: 256 -> 1024 0:00:00 load avg: 1.44 Run tests sequentially 0:00:00 load avg: 1.44 [1/1] test_urllib2 beginning 6 repetitions 123456 ...... == Tests result: SUCCESS == 1 test OK. Total duration: 1.5 sec Tests result: SUCCESS |
Sorry, something went wrong.
✅ Deploy Preview for python-cpython-preview canceled.
|
Sorry, something went wrong.
There was a problem hiding this comment.
You made changes to _TemporaryFileCloser but urllib.response.addinfourl here is a subclass of _TemporaryFileWrapper. Now after your changes the .close() and .cleanup() operations work but the wrapper is still in an inconsistent state. It cannot be used as a context manager, and cannot be iterated. The wrapper proxies attribute access to the file handle so asking things like exc.mode, exc.seekable(), etc. will all fail.
The cleanest solution would be to change HTTPError to not subclass this thing at all... but that ship has sailed a long time ago.
Your change weakens _TemporaryFileCloser by allowing it to silently accept None in lieu of a file handle. This makes tempfile worse, I'm not convinced this is a good compromise.
Instead, since HTTPError is already a hack (and there was literally a comment about why it's hacky where the bug was created), I would just replace the hack with a different one: set fp to io.StringIO() if the passed fp is None. It's still not perfect but I feel that would be more robust.
Sorry, something went wrong.
|
When you're done making the requested changes, leave the comment: I have made the requested changes; please review again. |
Sorry, something went wrong.
+1 |
Sorry, something went wrong.
|
Thank you for the review and for pointing out what I missed :) I have made the requested changes; please review again |
Sorry, something went wrong.
|
Thanks for making the requested changes! @ambv: please review the changes made to this pull request. |
Sorry, something went wrong.
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
|
Thanks @corona10 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
Sorry, something went wrong.
|
GH-100096 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
… None (pythongh-99966) (cherry picked from commit dc8a868) Co-authored-by: Dong-hee Na <donghee.na@python.org>
… None (pythongh-99966) (cherry picked from commit dc8a868) Co-authored-by: Dong-hee Na <donghee.na@python.org>
|
GH-100097 is a backport of this pull request to the 3.10 branch. |
Sorry, something went wrong.
| if fp is not None: | ||
| self.__super_init(fp, hdrs, url, code) | ||
| if fp is None: | ||
| fp = io.StringIO() |
There was a problem hiding this comment.
Shouldn't this be BytesIO?
from urllib.request import urlopen
from urllib.error import HTTPError
try:
urlopen('http://asadsad.sd')
except HTTPError as exception:
content = exception.fp.read()
print(type(content))<class 'bytes'>
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.