ThirdPartyHook.call: encode/decode the hook's input/output

This commit is part of the prep work for the transition to Python 3.x,
where the input of the hooks need to be encoded before send it,
and where the output needs to be decoded.

Change-Id: I68fa9de5b4c8b932f931725174a6424716855c2a
TN: U530-006
This commit is contained in:
Joel Brobecker
2021-10-03 14:19:48 -07:00
parent 2178791fa7
commit 62fa030351

View File

@@ -1,5 +1,6 @@
from errors import InvalidUpdate
from git import git, CalledProcessError
from io_utils import encode_utf8, safe_decode
from type_conversions import to_type
import os
@@ -182,9 +183,11 @@ class ThirdPartyHook(object):
"{err_info}".format(self=self, err_info=str(E))
)
if hook_input is not None:
hook_input = encode_utf8(hook_input)
out, _ = p.communicate(hook_input)
return (self.hook_exe, p, out)
return (self.hook_exe, p, safe_decode(out))
def call_if_defined(self, hook_input=None, hook_args=None, cwd=None):
"""If defined, call the script specified via self.hook_option_name.