diff options
author | Denis Laxalde <denis.laxalde@logilab.fr> | 2017-07-04 09:24:36 +0200 |
---|---|---|
committer | Denis Laxalde <denis.laxalde@logilab.fr> | 2017-07-04 09:24:36 +0200 |
commit | 6a832d17a3555c652d5530625a40f73c69441720 (patch) | |
tree | 1e8aa87e32e53a77b2994c4e9b299d1ab6ba608d | |
parent | 57c1a89bc7ef582a85f291c976c932c59062a1ce (diff) | |
download | logilab-common-6a832d17a3555c652d5530625a40f73c69441720.tar.gz |
Use io.open() to avoid deprecation warning about 'U' mode
Use io.open() which has a consistent interface between Python 2 and Python 3.
In particular, `newline` parameter is meant to control "universal new lines"
and it is None by default so we don't need to specify it.
-rw-r--r-- | logilab/common/fileutils.py | 3 | ||||
-rw-r--r-- | test/unittest_fileutils.py | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/logilab/common/fileutils.py b/logilab/common/fileutils.py index 366d23d..48828fb 100644 --- a/logilab/common/fileutils.py +++ b/logilab/common/fileutils.py @@ -28,6 +28,7 @@ from __future__ import print_function __docformat__ = "restructuredtext en" +import io import sys import shutil import mimetypes @@ -282,7 +283,7 @@ def lines(path, comments=None): :warning: at some point this function will probably return an iterator """ - stream = open(path, 'U') + stream = io.open(path) result = stream_lines(stream, comments) stream.close() return result diff --git a/test/unittest_fileutils.py b/test/unittest_fileutils.py index 80cefe4..a43b60f 100644 --- a/test/unittest_fileutils.py +++ b/test/unittest_fileutils.py @@ -18,6 +18,7 @@ """unit tests for logilab.common.fileutils""" import doctest +import io import sys, os, tempfile, shutil from stat import S_IWRITE from os.path import join @@ -54,7 +55,7 @@ class GetModeTC(TestCase): class NormReadTC(TestCase): def test_known_values_norm_read(self): - data = open(NEWLINES_TXT, 'U').read() + data = io.open(NEWLINES_TXT).read() self.assertEqual(data.strip(), '\n'.join(['# mixed new lines', '1', '2', '3'])) |