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
This commit is contained in:
maruel@chromium.org
2012-07-03 16:08:15 +00:00
parent 9206738c68
commit dae209fb46
2 changed files with 7 additions and 14 deletions

View File

@@ -4,6 +4,7 @@
"""Generic utils."""
import codecs
import errno
import logging
import os
@@ -76,21 +77,13 @@ class PrintableObject(object):
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):