summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordy Ruiz <56157703+jordr@users.noreply.github.com>2023-01-07 23:11:36 +0100
committerGitHub <noreply@github.com>2023-01-07 14:11:36 -0800
commit5382e3119b84eabcb2369f70978e1b803cbd185a (patch)
tree76c4a3d5a5663b8fa745d55054f660de459d55e7
parent332e84e36670f4584fd644440b1c4c462413aec9 (diff)
downloadpycparser-5382e3119b84eabcb2369f70978e1b803cbd185a.tar.gz
Add encoding param to parse_file (#486)
-rw-r--r--pycparser/__init__.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/pycparser/__init__.py b/pycparser/__init__.py
index d82eb2d..842a81d 100644
--- a/pycparser/__init__.py
+++ b/pycparser/__init__.py
@@ -49,7 +49,7 @@ def preprocess_file(filename, cpp_path='cpp', cpp_args=''):
def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='',
- parser=None):
+ parser=None, encoding=None):
""" Parse a C file using pycparser.
filename:
@@ -71,6 +71,9 @@ def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='',
r'-I../utils/fake_libc_include'
If several arguments are required, pass a list of strings.
+ encoding:
+ Encoding to use for the file to parse
+
parser:
Optional parser object to be used instead of the default CParser
@@ -82,7 +85,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 io.open(filename) as f:
+ with io.open(filename, encoding=encoding) as f:
text = f.read()
if parser is None: