mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user