Skip to content

Commit

Permalink
py/makedefs: Use io.open with utf-8 encoding when processing source.
Browse files Browse the repository at this point in the history
In case (user) source code contains utf-8 encoded data and the default
locale is not utf-8.

See #4592.
  • Loading branch information
dpgeorge committed Apr 12, 2019
1 parent fd11223 commit 673e154
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion py/makemoduledefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from __future__ import print_function

import re
import io
import os
import argparse

Expand Down Expand Up @@ -49,7 +50,7 @@ def find_module_registrations(c_file):
# No c file to match the object file, skip
return set()

with open(c_file) as c_file_obj:
with io.open(c_file, encoding='utf-8') as c_file_obj:
return set(re.findall(pattern, c_file_obj.read()))


Expand Down
3 changes: 2 additions & 1 deletion py/makeqstrdefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import re
import sys
import io
import os

# Blacklist of qstrings that are specially handled in further
Expand Down Expand Up @@ -108,7 +109,7 @@ class Args:
pass

if args.command == "split":
with open(args.input_filename) as infile:
with io.open(args.input_filename, encoding='utf-8') as infile:
process_file(infile)

if args.command == "cat":
Expand Down

0 comments on commit 673e154

Please sign in to comment.