git-hyper-blame: Fix unicode handling.

git hyper_blame might use a subprocess' stdin for its stdout,
which is opened to accept byte input.
The text must be encoded before printing to stdout to avoid
unicode errors.

Bug: 1028709
Change-Id: If2a270a7f3f69a818d367616f6732245de364db9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1937500
Reviewed-by: Andy Perelson <ajp@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
diff --git a/git_hyper_blame.py b/git_hyper_blame.py
index 8b0ee30..44e3f8a 100755
--- a/git_hyper_blame.py
+++ b/git_hyper_blame.py
@@ -95,7 +95,7 @@
     yield BlameLine(commit, context, lineno_then, lineno_now, False)
 
 
-def print_table(table, colsep=' ', rowsep='\n', align=None, out=sys.stdout):
+def print_table(table, align=None, out=sys.stdout):
   """Print a 2D rectangular array, aligning columns with spaces.
 
   Args:
@@ -124,9 +124,10 @@
       elif i < len(row) - 1:
         # Do not pad the final column if left-aligned.
         cell += padding
+      cell = cell.encode('utf-8', 'replace')
       cells.append(cell)
     try:
-      print(*cells, sep=colsep, end=rowsep, file=out)
+      out.write(b' '.join(cells) + b'\n')
     except IOError:  # pragma: no cover
       # Can happen on Windows if the pipe is closed early.
       pass