Commit dae209fb authored by maruel@chromium.org's avatar maruel@chromium.org

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
parent 9206738c
......@@ -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):
......
......@@ -37,9 +37,9 @@ class GclientUtilsUnittest(GclientUtilBase):
'PrintableObject', 'RemoveDirectory', 'RunEditor',
'SplitUrlRevision', 'SyntaxErrorToError',
'UpgradeToHttps', 'Wrapper', 'WorkItem',
'errno', 'lockedmethod', 'logging', 'os', 'Queue', 're', 'rmtree',
'safe_makedirs', 'stat', 'subprocess2', 'sys', 'tempfile', 'threading',
'time', 'urlparse',
'codecs', 'errno', 'lockedmethod', 'logging', 'os', 'Queue', 're',
'rmtree', 'safe_makedirs', 'stat', 'subprocess2', 'sys', 'tempfile',
'threading', 'time', 'urlparse',
]
# If this test fails, you should add the relevant test.
self.compareMembers(gclient_utils, members)
......
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