Subject: [xml2rfc] #340 (Version 2 cli): Deprecation warning when running with python3

From: "xml2rfc issue tracker" <[email-masked]>
Date: Sat, 20 Jan 2018 02:57:08 -0000

#340: Deprecation warning when running with python3

 Running 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:

 diff --git a/xml2rfc/parser.py b/xml2rfc/parser.py
 index 9bd0631..03b4a25 100644
 --- a/xml2rfc/parser.py
 +++ b/xml2rfc/parser.py
 @@ -437,7 +437,7 @@ class XmlRfcParser:
          if six.PY2:
              self.text = open(self.source, "rU").read()
          else:
 -            self.text = open(self.source, "rUb").read()
 +            self.text = open(self.source, "rb").read()

          # Get an iterating parser object
          file = six.BytesIO(self.text)

 Thanks for your work on xml2rfc,

 Scott K

-- 
--------------------------------+----------------------------------
 Reporter:  [email-masked]  |      Owner:  [email-masked]
     Type:  defect              |     Status:  new
 Priority:  medium              |  Milestone:
Component:  Version 2 cli       |    Version:  2.4.x
 Keywords:                      |
--------------------------------+----------------------------------

Ticket URL: <https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/340>
xml2rfc <http://tools.ietf.org/tools/xml2rfc/>

---

From: "xml2rfc issue tracker" <[email-masked]>
Date: Sat, 20 Jan 2018 02:58:13 -0000

Comment (by [email-masked]):

 Trac didn't handle my diff very well.  To be clear, the fix is to delete
 the "U" from line 440.

 Scott K

-- 
---------------------------------+----------------------------------
Resolution:                      |   Keywords:
---------------------------------+----------------------------------

Ticket URL: <https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/340#comment:1>
xml2rfc <http://tools.ietf.org/tools/xml2rfc/>

---

From: "xml2rfc issue tracker" <[email-masked]>
Date: Sat, 20 Jan 2018 16:02:30 -0000

> Thanks for your work on xml2rfc,

New description:

 {{{

 }}}

 Scott K

--

Comment (by [email-masked]):

 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.

Ticket URL: <https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/340#comment:2>
xml2rfc <http://tools.ietf.org/tools/xml2rfc/>

---

From: "xml2rfc issue tracker" <[email-masked]>
Date: Sun, 21 Jan 2018 06:39:55 -0000

I checked the documentation and whatever it was there for, it serves no
 purpose how.  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

Ticket URL: <https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/340#comment:3>
xml2rfc <http://tools.ietf.org/tools/xml2rfc/>

---

From: "xml2rfc issue tracker" <[email-masked]>
Date: Sun, 21 Jan 2018 19:42:50 -0000

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()

 (Running tests under Py3.5, there was also a warning for the dangling open
 file created by the earlier code).

Ticket URL: <https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/340#comment:4>
xml2rfc <http://tools.ietf.org/tools/xml2rfc/>

---

From: "xml2rfc issue tracker" <[email-masked]>
Date: Sun, 21 Jan 2018 19:53:22 -0000

Changes (by [email-masked]):

 * status:  new => closed
 * resolution:   => fixed

Comment:

 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
 [email-masked] for
     pointing that out).  Also changed the code to avoid a dangling open
 file
     handle.

-- 
---------------------------------+----------------------------------
  Reporter:  [email-masked]  |      Owner:  [email-masked]
      Type:  defect              |     Status:  closed
  Priority:  medium              |  Milestone:
 Component:  Version 2 cli       |    Version:  2.4.x
Resolution:  fixed               |   Keywords:
---------------------------------+----------------------------------

Ticket URL: <https://trac.tools.ietf.org/tools/xml2rfc/trac/ticket/340#comment:5>
xml2rfc <http://tools.ietf.org/tools/xml2rfc/>