Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an encoding parameter to parse_file #486

Merged
merged 1 commit into from Jan 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions pycparser/__init__.py
Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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:
Expand Down