Skip to content

Commit 9294868

Browse files
authored
Merge pull request #30 from vilius-g/fix-pathconf-unicodeencodeerror
Fixed UnicodeEncodeError when creating OSFS from non-ascii path
2 parents 7aa51be + 78400af commit 9294868

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

fs/osfs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ def __init__(self,
110110
_meta["invalid_path_chars"] = '\0'
111111

112112
if 'PC_PATH_MAX' in os.pathconf_names:
113+
root_path_safe = _root_path.encode(self.encoding) \
114+
if six.PY2 and isinstance(_root_path, six.text_type) \
115+
else _root_path
113116
_meta['max_sys_path_length'] = (
114117
os.pathconf(
115-
_root_path,
118+
root_path_safe,
116119
os.pathconf_names['PC_PATH_MAX']
117120
)
118121
)

tests/test_osfs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,13 @@ def test_create(self):
8484
with self.assertRaises(errors.CreateFailed):
8585
# Trying to create a dir that exists as a file
8686
osfs.OSFS(tmp_file.name, create=True)
87+
88+
def test_unicode_paths(self):
89+
dir_path = tempfile.mkdtemp()
90+
try:
91+
fs_dir = os.path.join(dir_path, u'te\u0161t_\u00fanicod\u0113')
92+
os.mkdir(fs_dir)
93+
with osfs.OSFS(fs_dir):
94+
self.assertTrue(os.path.isdir(fs_dir))
95+
finally:
96+
shutil.rmtree(dir_path)

0 commit comments

Comments
 (0)