Convert path to string right before passing it to the filesystem layer
This commit is contained in:
parent
7fe25a5872
commit
5ef85fc6c8
@ -49,7 +49,7 @@ class FileIO(object):
|
||||
"""
|
||||
|
||||
def __init__(self, name, mode):
|
||||
self.__name = compat.path_to_str(name)
|
||||
self.__name = name
|
||||
self.__mode = mode
|
||||
self._read_buf = None
|
||||
self._writable_file = None
|
||||
@ -77,7 +77,7 @@ class FileIO(object):
|
||||
raise errors.PermissionDeniedError(None, None,
|
||||
"File isn't open for reading")
|
||||
self._read_buf = _pywrap_file_io.BufferedInputStream(
|
||||
self.__name, 1024 * 512)
|
||||
compat.path_to_str(self.__name), 1024 * 512)
|
||||
|
||||
def _prewrite_check(self):
|
||||
if not self._writable_file:
|
||||
@ -85,7 +85,7 @@ class FileIO(object):
|
||||
raise errors.PermissionDeniedError(None, None,
|
||||
"File isn't open for writing")
|
||||
self._writable_file = _pywrap_file_io.WritableFile(
|
||||
compat.as_bytes(self.__name), compat.as_bytes(self.__mode))
|
||||
compat.path_to_bytes(self.__name), compat.as_bytes(self.__mode))
|
||||
|
||||
def _prepare_value(self, val):
|
||||
if self._binary_mode:
|
||||
|
@ -50,10 +50,6 @@ class FileIoTest(test.TestCase, parameterized.TestCase):
|
||||
with self.assertRaises(errors.NotFoundError):
|
||||
_ = f.read()
|
||||
|
||||
def testPathLike(self):
|
||||
f = file_io.FileIO(pathlib.Path("temp_file"), mode="w")
|
||||
self.assertEqual(f.name, "temp_file")
|
||||
|
||||
@run_all_path_types
|
||||
def testFileDoesntExist(self, join):
|
||||
file_path = join(self._base_dir, "temp_file")
|
||||
@ -88,14 +84,16 @@ class FileIoTest(test.TestCase, parameterized.TestCase):
|
||||
file_contents = file_io.read_file_to_string(file_path)
|
||||
self.assertEqual("new", file_contents)
|
||||
|
||||
def testReadBinaryMode(self):
|
||||
file_path = os.path.join(self._base_dir, "temp_file")
|
||||
@run_all_path_types
|
||||
def testReadBinaryMode(self, join):
|
||||
file_path = join(self._base_dir, "temp_file")
|
||||
file_io.write_string_to_file(file_path, "testing")
|
||||
with file_io.FileIO(file_path, mode="rb") as f:
|
||||
self.assertEqual(b"testing", f.read())
|
||||
|
||||
def testWriteBinaryMode(self):
|
||||
file_path = os.path.join(self._base_dir, "temp_file")
|
||||
@run_all_path_types
|
||||
def testWriteBinaryMode(self, join):
|
||||
file_path = join(self._base_dir, "temp_file")
|
||||
file_io.FileIO(file_path, "wb").write("testing")
|
||||
with file_io.FileIO(file_path, mode="r") as f:
|
||||
self.assertEqual("testing", f.read())
|
||||
|
Loading…
Reference in New Issue
Block a user