-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-30264: ExpatParser closes the source on error #1451
Conversation
@Haypo, thanks for your PR! By analyzing the history of the files in this pull request, we identified @bitdancer, @serhiy-storchaka and @loewis to be potential reviewers. |
ExpatParser.parse() of xml.sax.xmlreader now always closes the source: close the file object or the urllib object if source is a string (not an open file-like object). The change fixes a ResourceWarning on parsing error. Add test_parse_close_source() unit test.
Codecov Report
@@ Coverage Diff @@
## master #1451 +/- ##
==========================================
+ Coverage 83.44% 83.44% +<.01%
==========================================
Files 1368 1368
Lines 346460 346477 +17
==========================================
+ Hits 289099 289130 +31
+ Misses 57361 57347 -14
Continue to review full report at Codecov.
|
ExpatParser.parse() of xml.sax.xmlreader now always closes the source: close the file object or the urllib object if source is a string (not an open file-like object). The change fixes a ResourceWarning on parsing error. Add test_parse_close_source() unit test. (cherry picked from commit ef9c0e7)
ExpatParser.parse() of xml.sax.xmlreader now always closes the source: close the file object or the urllib object if source is a string (not an open file-like object). The change fixes a ResourceWarning on parsing error. Add test_parse_close_source() unit test. (cherry picked from commit ef9c0e7)
Sorry if this is the wrong place to post this. We hit some issues with this change (which could be due to my own misunderstandings, let me know if that's the case!) My questions are:
For file descriptors that point to files on disk we can work around it by reopening the file, but for something like a StringIO buffer (see simplified example below) I'm not aware of any way to get around the problem. import xml.sax
import StringIO
# Some StringIO buffer.
source = StringIO.StringIO(b'<_/>')
# Do some parsing.
xml.sax.parse(source, xml.sax.handler.ContentHandler())
# Try to do some other parsing (fails).
xml.sax.parse(source, xml.sax.handler.ContentHandler()) EDIT: This should probably have been on #1476 |
The issue on the Python bug tracker is better place: https://bugs.python.org/issue30264. GitHub is only for discussing technical details of a concrete PR. This PR was merged a year ago. |
Thanks @serhiy-storchaka , raised https://bugs.python.org/issue33732 |
ExpatParser.parse() of xml.sax.xmlreader now always closes the
source: close the file object or the urllib object if source is a
string (not an open file-like object). The change fixes a
ResourceWarning on parsing error.
Add test_parse_close_source() unit test.