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

mojo: Fix writing bytes to files on Python 3

Avoids having decode()s at callsites.

Traceback (most recent call last):
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 556, in <module>
    sys.exit(main())
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 551, in main
    return args.func(args, remaining_args)
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 334, in _Parse
    _ParseFile(args, RelativePath(filename, args.depth))
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 323, in _ParseFile
    _PickleAST(tree, _GetPicklePath(rel_filename, args.output_dir))
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 295, in _PickleAST
    WriteFile(pickle.dumps(ast), output_file)
  File "C:\Google\chromium\src\mojo\public\tools\bindings\pylib\mojom\generate\generator.py", line 118, in WriteFile
    f.write(contents.encode('utf-8'))
AttributeError: 'bytes' object has no attribute 'encode'

Bug: 941669
Change-Id: I116e469dd5ff7903779226b7ea18cdd5e4cc2fe7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2031112
Commit-Queue: Ken Rockot <rockot@google.com>
Auto-Submit: Raul Tambre <raul@tambre.ee>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#738039}
parent 1bdff69d
...@@ -112,7 +112,10 @@ def WriteFile(contents, full_path): ...@@ -112,7 +112,10 @@ def WriteFile(contents, full_path):
# Dump the data to disk. # Dump the data to disk.
with open(full_path, "wb") as f: with open(full_path, "wb") as f:
f.write(contents.encode('utf-8')) if type(contents) != bytes:
f.write(contents.encode('utf-8'))
else:
f.write(contents)
def AddComputedData(module): def AddComputedData(module):
......
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