Commit d9c1c856 authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

fix_encoding: Decode bytestrings on Python 3

Strings need to be passed to WriteConsoleW, otherwise an exception will be thrown:
<Unicode console <stdout>>.write: ArgumentError("argument 2: <class 'TypeError'>: wrong type")
Traceback (most recent call last):
  File "C:\Google\depot_tools\metrics.py", line 267, in print_notice_and_exit
    yield
  File "C:\Google\depot_tools\gclient.py", line 3156, in <module>
    sys.exit(main(sys.argv[1:]))
  File "C:\Google\depot_tools\gclient.py", line 3142, in main
    return dispatcher.execute(OptionParser(), argv)
  File "C:\Google\depot_tools\subcommand.py", line 252, in execute
    return command(parser, args[1:])
  File "C:\Google\depot_tools\gclient.py", line 2699, in CMDsync
    ret = client.RunOnDeps('update', args)
  File "C:\Google\depot_tools\gclient.py", line 1771, in RunOnDeps
    self.RunHooksRecursively(self._options, pm)
  File "C:\Google\depot_tools\gclient.py", line 1064, in RunHooksRecursively
    hook.run()
  File "C:\Google\depot_tools\gclient.py", line 255, in run
    gclient_utils.CheckCallAndFilter(
  File "C:\Google\depot_tools\gclient_utils.py", line 592, in CheckCallAndFilter
    stdout_write(in_byte)
  File "C:\Google\depot_tools\gclient_utils.py", line 375, in write
    return self._wrapped.write(out)
  File "C:\Google\depot_tools\gclient_utils.py", line 343, in write
    self._wrapped.write(out, *args, **kwargs)
  File "C:\Google\depot_tools\fix_encoding.py", line 224, in write
    retval = self._WriteConsoleW(
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

Bug: 984182
Change-Id: Icffe0e0ea1fe2be5bc7607e32f58605d02f1f870
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1778746
Commit-Queue: Raul Tambre <raul@tambre.ee>
Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
Auto-Submit: Raul Tambre <raul@tambre.ee>
parent e5641be5
......@@ -215,6 +215,10 @@ class WinUnicodeConsoleOutput(WinUnicodeOutputBase):
if sys.version_info.major == 2 and not isinstance(text, unicode):
# Convert to unicode.
text = str(text).decode(self.encoding, 'replace')
elif sys.version_info.major == 3 and isinstance(text, bytes):
# Bytestrings need to be decoded to a string before being passed to
# Windows.
text = text.decode(self.encoding, 'replace')
remaining = len(text)
while remaining > 0:
n = self._DWORD(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment