From f03e2d533612ebe5f91a414e7d7a16002fa30c0a Mon Sep 17 00:00:00 2001 From: Jordy Ruiz Date: Thu, 5 Jan 2023 10:39:10 +0100 Subject: [PATCH] Add encoding param to parse_file --- pycparser/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pycparser/__init__.py b/pycparser/__init__.py index d82eb2d6..842a81dd 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: