Closed hassanakbar4 closed 3 years ago
@{"email"=>"scott@kitterman.com", "name"=>nil, "username"=>nil} commented
Trac didn't handle my diff very well. To be clear, the fix is to delete the "U" from line 440.
Scott K
@{"email"=>"henrik@levkowetz.com", "name"=>nil, "username"=>nil} edited the issue description
@{"email"=>"henrik@levkowetz.com", "name"=>nil, "username"=>nil} commented
Thanks, Scott.
However, I'm not sure the fix is that simple -- there's a reason why the Universal newline flag was needed (even if I don't recall what prompted it, without going back in the commit history). Removing the 'U' flag would also mean investigating why it was needed, and probably adding code to handle newline normalization after reading the file.
@{"email"=>"scott@kitterman.com", "name"=>nil, "username"=>nil} changed _comment0 which not transferred by tractive
@{"email"=>"scott@kitterman.com", "name"=>nil, "username"=>nil} commented
I checked the documentation and whatever it was there for, it serves no purpose now. Here's what help(open) has to say about it in python3.4:
'U' mode is deprecated and will raise an exception in future versions
of Python. It has no effect in Python 3. Use newline to control
universal newlines mode.
Thanks for fixing the description.
Scott K
@{"email"=>"henrik@levkowetz.com", "name"=>nil, "username"=>nil} commented
Sure, and thanks for the help text pointing at the newline= parameter.
Now running tests for the diff:
Index: xml2rfc/parser.py
===================================================================
--- xml2rfc/parser.py (revision 2404)
+++ xml2rfc/parser.py (working copy)
@@ -435,9 +435,11 @@
xml2rfc.log.write('Parsing file', self.source)
if six.PY2:
- self.text = open(self.source, "rU").read()
+ with open(self.source, "rU") as f:
+ self.text = f.read()
else:
- self.text = open(self.source, "rUb").read()
+ with open(self.source, "rb", newline=None) as f:
+ self.text = f.read()
# Get an iterating parser object
file = six.BytesIO(self.text)
(Running tests under Py3.5, there was also a warning for the dangling open file created by the earlier code).
@{"email"=>"henrik@levkowetz.com", "name"=>nil, "username"=>nil} changed status from new
to closed
@{"email"=>"henrik@levkowetz.com", "name"=>nil, "username"=>nil} changed resolution from ` to
fixed`
@{"email"=>"henrik@levkowetz.com", "name"=>nil, "username"=>nil} commented
Fixed in [2405]:
Changed a file open mode under python3 to use the newline= parameter to
open() instead of the deprecated 'U' mode (thanks to spf2@kitterman.com for
pointing that out). Also changed the code to avoid a dangling open file
handle.
component_Version 2 cli
resolution_fixed
type_defect
| by scott@kitterman.comRunning the tests with the current (and probably any) xml2rfc version on python3 yields the following warning:
test_header_footer (main.WriterDraftTest) ... /tmp/buildd/xml2rfc-2.8.4/xml2rfc/parser.py:440: DeprecationWarning: 'U' mode is deprecated self.text = open(self.source, "rUb").read()
It would be nice to see this resolved before it turns into an error. The fix is trivial:
Thanks for your work on xml2rfc,
Scott K
Issue migrated from trac:340 at 2021-10-20 18:25:35 +0500