From 62fa030351a0842657d5cad4d3d0f8fa88f9eb9b Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Sun, 3 Oct 2021 14:19:48 -0700 Subject: [PATCH] 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 --- hooks/config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hooks/config.py b/hooks/config.py index fed663b..53c6255 100644 --- a/hooks/config.py +++ b/hooks/config.py @@ -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.