Skip to content

Commit

Permalink
Add encoding param to parse_file
Browse files Browse the repository at this point in the history
  • Loading branch information
jordr committed Jan 5, 2023
1 parent f5ca028 commit f03e2d5
Showing 1 changed file with 5 additions and 2 deletions.
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

0 comments on commit f03e2d5

Please sign in to comment.