Skip to content

Commit 2b430ac

Browse files
committed
Specify utf-8 encoding when reading/writing plain text files
1 parent bb51cf7 commit 2b430ac

5 files changed

Lines changed: 10 additions & 11 deletions

File tree

pre_commit_hooks/check_autopkg_recipe_list.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def main(argv=None):
3737
for filename in args.filenames:
3838
recipe_list = None
3939
if filename.endswith(".txt"):
40-
with open(filename, "r") as openfile:
40+
with open(filename, "r", encoding="utf-8") as openfile:
4141
recipe_list = [
4242
line
4343
for line in openfile.read().splitlines()
@@ -54,7 +54,7 @@ def main(argv=None):
5454
# AutoPkg does not support YAML recipe lists, but AutoPkg users
5555
# may have developed custom tooling for this.
5656
try:
57-
with open(filename, "r") as openfile:
57+
with open(filename, "r", encoding="utf-8") as openfile:
5858
recipe_list = yaml.load(openfile)
5959
except Exception as err:
6060
print("{}: yaml parsing error: {}".format(filename, err))
@@ -63,7 +63,7 @@ def main(argv=None):
6363
# AutoPkg does not support JSON recipe lists, but AutoPkg users
6464
# may have developed custom tooling for this.
6565
try:
66-
with open(filename, "r") as openfile:
66+
with open(filename, "r", encoding="utf-8") as openfile:
6767
recipe_list = json.load(openfile)
6868
except Exception as err:
6969
print("{}: json parsing error: {}".format(filename, err))

pre_commit_hooks/check_autopkg_recipes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Import AutoPkg libraries, but ignore any warnings generated by the import.
2121
@contextmanager
2222
def suppress_stdout():
23-
with open(os.devnull, "w") as devnull:
23+
with open(os.devnull, "w", encoding="utf-8") as devnull:
2424
old_stdout = sys.stdout
2525
sys.stdout = devnull
2626
try:
@@ -100,7 +100,7 @@ def validate_comments(filename, strict):
100100
plutil -convert xml1."""
101101

102102
passed = True
103-
with open(filename, "r") as openfile:
103+
with open(filename, "r", encoding="utf-8") as openfile:
104104
recipe_text = openfile.read()
105105
if "<!--" in recipe_text and "-->" in recipe_text:
106106
if strict:
@@ -548,7 +548,7 @@ def main(argv=None):
548548
break # No need to continue checking this file
549549

550550
# For future implementation of validate_unused_input_vars()
551-
# with open(filename, "r") as openfile:
551+
# with open(filename, "r", encoding='utf-8') as openfile:
552552
# recipe_text = openfile.read()
553553

554554
# Top level keys that all AutoPkg recipes should contain.

pre_commit_hooks/check_jamf_extension_attributes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def main(argv=None):
2525

2626
retval = 0
2727
for filename in args.filenames:
28-
with open(filename, "r") as openfile:
28+
with open(filename, "r", encoding="utf-8") as openfile:
2929
ea_content = openfile.read()
3030

3131
if "<result>" not in ea_content or "</result>" not in ea_content:

pre_commit_hooks/check_jamf_scripts.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""Check Jamf scripts for common issues."""
44

55
import argparse
6-
import os
76

87

98
def build_argument_parser():
@@ -25,7 +24,7 @@ def main(argv=None):
2524

2625
retval = 0
2726
for filename in args.filenames:
28-
with open(filename, "r") as openfile:
27+
with open(filename, "r", encoding="utf-8") as openfile:
2928
script_content = openfile.read()
3029

3130
# Ensure script starts with a shebang of some sort.

pre_commit_hooks/check_munkipkg_buildinfo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ def main(argv=None):
8989
break # no need to continue testing this file
9090
elif filename.endswith((".yaml", ".yml")):
9191
try:
92-
with open(filename, "r") as openfile:
92+
with open(filename, "r", encoding="utf-8") as openfile:
9393
buildinfo = yaml.load(openfile)
9494
except Exception as err:
9595
print("{}: yaml parsing error: {}".format(filename, err))
9696
retval = 1
9797
break # no need to continue testing this file
9898
elif filename.endswith(".json"):
9999
try:
100-
with open(filename, "r") as openfile:
100+
with open(filename, "r", encoding="utf-8") as openfile:
101101
buildinfo = json.load(openfile)
102102
except Exception as err:
103103
print("{}: json parsing error: {}".format(filename, err))

0 commit comments

Comments
 (0)