Skip to content

Commit 8564de8

Browse files
committed
Convert str filter patterns to bytes in Python 3
1 parent 576fc7e commit 8564de8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

vagrant/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -979,17 +979,18 @@ def _filter_vagrant_command(self, args, output_filter):
979979
:rtype: dict
980980
"""
981981
assert isinstance(output_filter, dict)
982-
if sys.version_info > (3, 0):
983-
py3 = True
984-
else:
985-
py3 = False
982+
py3 = sys.version_info > (3, 0)
986983

987984
# Create dictionary that will store the results from the filters
988985
filter_results = dict.fromkeys(output_filter)
989986

990987
for f in output_filter.keys():
991988
# Check the filter values, compile as regular expression objects if necessary
992989
if not isinstance(output_filter[f]['pat'], type(re.compile(''))):
990+
if py3 and isinstance(output_filter[f]['pat'], str):
991+
# In Python 3, the output from subprocess will be bytes, so the pattern has to be bytes as well
992+
# for it to match.
993+
output_filter[f]['pat'] = output_filter[f]['pat'].encode()
993994
try:
994995
output_filter[f]['pat'] = re.compile(output_filter[f]['pat'])
995996
except TypeError:

0 commit comments

Comments
 (0)