Commit 48614441 authored by Yura Yaroshevich's avatar Yura Yaroshevich Committed by Commit Bot

Specify open file encoding explicitly.

This fixes an error on some Windows installations:
```
fetch webrtc
Traceback (most recent call last):
  File "googlesource.com\depot_tools\bootstrap\bootstrap.py", line 365, in <module>
    sys.exit(main(sys.argv[1:]))
  File "googlesource.com\depot_tools\bootstrap\bootstrap.py", line 324, in main
    git_postprocess(template, os.path.join(bootstrap_dir, 'git'))
  File "googlesource.com\depot_tools\bootstrap\bootstrap.py", line 264, in git_postprocess
    maybe_copy(
  File "googlesource.com\depot_tools\bootstrap\bootstrap.py", line 108, in maybe_copy
    content = fd.read()
  File "googlesource.com\depot_tools\bootstrap-3_8_0b1_chromium_1_bin\python3\bin\lib\encodings\cp1251.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]

UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 18734: character maps to <undefined>
```
Bug: None
Change-Id: I43cf7b51879ac9a66c33566536dcdcb4c93e0fc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1881227Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent 86244d69
......@@ -60,7 +60,7 @@ class Template(collections.namedtuple('Template', (
Returns (bool): True if |dst_path| was updated, False otherwise.
"""
template_path = os.path.join(THIS_DIR, name)
with open(template_path, 'r') as fd:
with open(template_path, 'r', encoding='utf8') as fd:
t = string.Template(fd.read())
return maybe_update(t.safe_substitute(self._asdict()), dst_path)
......@@ -82,12 +82,12 @@ def maybe_update(content, dst_path):
# If the path already exists and matches the new content, refrain from writing
# a new one.
if os.path.exists(dst_path):
with open(dst_path, 'r') as fd:
with open(dst_path, 'r', encoding='utf-8') as fd:
if fd.read() == content:
return False
logging.debug('Updating %r', dst_path)
with open(dst_path, 'w') as fd:
with open(dst_path, 'w', encoding='utf-8') as fd:
fd.write(content)
os.chmod(dst_path, 0o755)
return True
......@@ -104,7 +104,7 @@ def maybe_copy(src_path, dst_path):
Returns (bool): True if |dst_path| was updated, False otherwise.
"""
with open(src_path, 'r') as fd:
with open(src_path, 'r', encoding='utf-8') as fd:
content = fd.read()
return maybe_update(content, dst_path)
......@@ -130,14 +130,14 @@ def call_if_outdated(stamp_path, stamp_version, fn):
stamp_version = stamp_version.strip()
if os.path.isfile(stamp_path):
with open(stamp_path, 'r') as fd:
with open(stamp_path, 'r', encoding='utf-8') as fd:
current_version = fd.read().strip()
if current_version == stamp_version:
return False
fn()
with open(stamp_path, 'w') as fd:
with open(stamp_path, 'w', encoding='utf-8') as fd:
fd.write(stamp_version)
return True
......
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