Use io.open vs raw open
The io.open call can take in a encoding so we don't need to read in binary mode, then convert it since it can just do that on our behalf. Change-Id: I0cce2841b40f1566ba07ff95a553cb18ea9059ee
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
import contextlib
|
||||
import errno
|
||||
import io
|
||||
import os
|
||||
import shutil
|
||||
|
||||
@@ -98,16 +99,15 @@ class Connection(path_based.PathBasedConnection):
|
||||
mtime = os.path.getmtime(filename)
|
||||
cache_info = self.backend.file_cache.setdefault(filename, {})
|
||||
if not cache_info or mtime > cache_info.get('mtime', 0):
|
||||
with open(filename, 'rb') as fp:
|
||||
cache_info['data'] = misc.binary_decode(
|
||||
fp.read(), encoding=self.backend.encoding)
|
||||
with io.open(filename, 'r', encoding=self.backend.encoding) as fp:
|
||||
cache_info['data'] = fp.read()
|
||||
cache_info['mtime'] = mtime
|
||||
return cache_info['data']
|
||||
|
||||
def _write_to(self, filename, contents):
|
||||
contents = misc.binary_encode(contents,
|
||||
encoding=self.backend.encoding)
|
||||
with open(filename, 'wb') as fp:
|
||||
with io.open(filename, 'wb') as fp:
|
||||
fp.write(contents)
|
||||
self.backend.file_cache.pop(filename, None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user