-
-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
Python 2.7.15: xml.sax.parse() closes file objects passed to it #77913
Comments
Sorry if this is a duplicate, I didn't find anything. We hit some issues with this change:
It's possible I'm misunderstanding something, let me know if that's the case. It seems that in Python 2.7.15, xml.sax.parse() closes file descriptors that are passed to it.
For file descriptors that point to files on disk we can work around it by reopening the file after each parse, but for something like a StringIO buffer (see simplified example below) I'm not aware of any way to get around the problem. -> StringIO Example: import xml.sax
import StringIO
# Some StringIO buffer.
fd = StringIO.StringIO(b'<_/>')
# Do some parsing.
xml.sax.parse(fd, xml.sax.handler.ContentHandler())
# Try to do some other parsing (fails).
xml.sax.parse(fd, xml.sax.handler.ContentHandler()) -> File Example: import xml.sax
fd = open('/tmp/test-junit1.xml')
# Do some parsing.
xml.sax.parse(fd, xml.sax.handler.ContentHandler())
# Do some other parsing.
xml.sax.parse(fd, xml.sax.handler.ContentHandler()) Originally posted on #1451 (comment), thanks serhiy.storchaka for redirecting me here. |
As an addendum, I note that other parsers, like: parser = lxml.etree.XMLParser(compact=False)
etree.parse(some_fd, parser).find('some_text').text do not close the fd they are given. |
Hi Gibson, I'm sorry this issue didn't get any attention before Python 2.7 reached EOL, but as that milestone has now passed I'm closing the issue. Thank you for the report anyway! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: