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 contextlib
|
||||||
import errno
|
import errno
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
@@ -98,16 +99,15 @@ class Connection(path_based.PathBasedConnection):
|
|||||||
mtime = os.path.getmtime(filename)
|
mtime = os.path.getmtime(filename)
|
||||||
cache_info = self.backend.file_cache.setdefault(filename, {})
|
cache_info = self.backend.file_cache.setdefault(filename, {})
|
||||||
if not cache_info or mtime > cache_info.get('mtime', 0):
|
if not cache_info or mtime > cache_info.get('mtime', 0):
|
||||||
with open(filename, 'rb') as fp:
|
with io.open(filename, 'r', encoding=self.backend.encoding) as fp:
|
||||||
cache_info['data'] = misc.binary_decode(
|
cache_info['data'] = fp.read()
|
||||||
fp.read(), encoding=self.backend.encoding)
|
|
||||||
cache_info['mtime'] = mtime
|
cache_info['mtime'] = mtime
|
||||||
return cache_info['data']
|
return cache_info['data']
|
||||||
|
|
||||||
def _write_to(self, filename, contents):
|
def _write_to(self, filename, contents):
|
||||||
contents = misc.binary_encode(contents,
|
contents = misc.binary_encode(contents,
|
||||||
encoding=self.backend.encoding)
|
encoding=self.backend.encoding)
|
||||||
with open(filename, 'wb') as fp:
|
with io.open(filename, 'wb') as fp:
|
||||||
fp.write(contents)
|
fp.write(contents)
|
||||||
self.backend.file_cache.pop(filename, None)
|
self.backend.file_cache.pop(filename, None)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user