aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2018-06-26 13:48:31 -0700
committerEli Bendersky <eliben@users.noreply.github.com>2018-06-26 13:48:31 -0700
commit13224c18fa95f060b6df9c6e6fd09081775568f5 (patch)
treec67562c5f6e9fb7881d9012f6c585a46258815fc
parent443474e4f33c20c87a5af87f83737302f1617b66 (diff)
downloadplatform_external_python_pycparser-13224c18fa95f060b6df9c6e6fd09081775568f5.tar.gz
platform_external_python_pycparser-13224c18fa95f060b6df9c6e6fd09081775568f5.tar.bz2
platform_external_python_pycparser-13224c18fa95f060b6df9c6e6fd09081775568f5.zip
Avoid opening files with deprecated 'U' mode (#269)
Opening files with 'U' mode is deprecated. When running tests with Python warnings enabled, the warnings of the following form are emitted: DeprecationWarning: 'U' mode is deprecated return open(name, 'rU') To open files with universal newlines on both Ptyhon 2 & 3, use the io module. It defaults to opening with universal newlines and doesn't emit a warning. https://docs.python.org/3/library/io.html > When reading input from the stream, if newline is None, universal > newlines mode is enabled.
-rw-r--r--pycparser/__init__.py3
-rwxr-xr-xtests/test_c_parser.py3
2 files changed, 4 insertions, 2 deletions
diff --git a/pycparser/__init__.py b/pycparser/__init__.py
index b7228d7..6ba6065 100644
--- a/pycparser/__init__.py
+++ b/pycparser/__init__.py
@@ -10,6 +10,7 @@
__all__ = ['c_lexer', 'c_parser', 'c_ast']
__version__ = '2.18'
+import io
from subprocess import check_output
from .c_parser import CParser
@@ -81,7 +82,7 @@ def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='',
if use_cpp:
text = preprocess_file(filename, cpp_path, cpp_args)
else:
- with open(filename, 'rU') as f:
+ with io.open(filename) as f:
text = f.read()
if parser is None:
diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py
index fd85c0d..7dad124 100755
--- a/tests/test_c_parser.py
+++ b/tests/test_c_parser.py
@@ -3,6 +3,7 @@
import pprint
import re
import os, sys
+import io
import unittest
sys.path[0:0] = ['.', '..']
@@ -1772,7 +1773,7 @@ class TestCParser_whole_code(TestCParser_base):
testdir = os.path.dirname(__file__)
name = os.path.join(testdir, 'c_files', name)
assert os.path.exists(name)
- return open(name, 'rU')
+ return io.open(name)
def test_whole_file(self):
# See how pycparser handles a whole, real C file.