Skip to content

Commit

Permalink
Fall back to ascii when getfilesystemencoding returns None. (#60)
Browse files Browse the repository at this point in the history
Closes issue #59.
  • Loading branch information
mcmtroffaes committed Sep 27, 2019
1 parent c8c155b commit e0e9fc3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ History
Version 2.3.5
^^^^^^^^^^^^^

- Fall back to ascii when getfilesystemencoding returns None (see
issue #59).

Version 2.3.4
^^^^^^^^^^^^^

Expand Down
6 changes: 5 additions & 1 deletion pathlib2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,11 @@ def _parse_args(cls, args):
# also handle unicode for PY2 (six.text_type = unicode)
elif six.PY2 and isinstance(a, six.text_type):
# cast to str using filesystem encoding
parts.append(a.encode(sys.getfilesystemencoding()))
# note: in rare circumstances, on Python < 3.2,
# getfilesystemencoding can return None, in that
# case fall back to ascii
parts.append(a.encode(
sys.getfilesystemencoding() or "ascii"))
else:
raise TypeError(
"argument should be a str object or an os.PathLike "
Expand Down

0 comments on commit e0e9fc3

Please sign in to comment.