Skip to content

Commit

Permalink
Fix a Python 3 compatibility issue in trytls.runner
Browse files Browse the repository at this point in the history
  • Loading branch information
jviide committed Aug 9, 2016
1 parent c350558 commit aaad3d8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions runners/trytls/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,20 @@ def run_one(args, host, port, cafile=None):
raise ProcessFailed("failed to launch the stub", os.strerror(ose.errno))

out, _ = process.communicate()
out = out.decode("ascii", "replace")

if process.returncode != 0:
raise ProcessFailed("stub exited with return code {}".format(process.returncode), out)

out = out.rstrip()
lines = out.splitlines()
if lines:
verdict = lines.pop()
if verdict == b"ACCEPT":
if verdict == "ACCEPT":
return True, "".join(lines)
elif verdict == b"REJECT":
elif verdict == "REJECT":
return False, "".join(lines)
elif verdict == b"UNSUPPORTED":
elif verdict == "UNSUPPORTED":
raise Unsupported("".join(lines))
raise UnexpectedOutput(out)

Expand Down Expand Up @@ -138,10 +140,13 @@ def format(self, test, res):
accept="accept" if test.accept else "reject"
)

if res.reason.rstrip():
template += reset + self.base + "\n" + indent("reason: " + self.reason + res.reason.rstrip(), by=6)
if res.details.rstrip():
template += reset + self.base + "\n" + indent("output: ", by=6) + self.details + indent(res.details.rstrip(), by=14, first_line=False)
reason = res.reason.rstrip()
if reason:
template += reset + self.base + "\n" + indent("reason: " + self.reason + reason, by=6)

details = res.details.rstrip()
if details:
template += reset + self.base + "\n" + indent("output: ", by=6) + self.details + indent(details, by=14, first_line=False)

return template

Expand Down

0 comments on commit aaad3d8

Please sign in to comment.