Enforce utf-8 codec on all files read and write.
Otherwise, the files are opened in 'whatever happens to be the current encoding'
which is highly system-dependent. Even if some files are not encoded with utf-8,
the status quo is even worse. So it's worth trying out.
TBR=cmp@chromium.org
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/10697036
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@145306 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gclient_utils.py b/gclient_utils.py
index 35f8b3b..9ba6da5 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -4,6 +4,7 @@
"""Generic utils."""
+import codecs
import errno
import logging
import os
@@ -76,21 +77,13 @@
def FileRead(filename, mode='rU'):
- content = None
- f = open(filename, mode)
- try:
- content = f.read()
- finally:
- f.close()
- return content
+ with codecs.open(filename, mode=mode, encoding='utf-8') as f:
+ return f.read()
def FileWrite(filename, content, mode='w'):
- f = open(filename, mode)
- try:
+ with codecs.open(filename, mode=mode, encoding='utf-8') as f:
f.write(content)
- finally:
- f.close()
def rmtree(path):