From 5382e3119b84eabcb2369f70978e1b803cbd185a Mon Sep 17 00:00:00 2001 From: Jordy Ruiz <56157703+jordr@users.noreply.github.com> Date: Sat, 7 Jan 2023 23:11:36 +0100 Subject: Add encoding param to parse_file (#486) --- pycparser/__init__.py | 7 +++++-- 1 file 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: -- cgit v1.2.1