Skip to content

Commit

Permalink
Merge 116c5d6 into ee3e335
Browse files Browse the repository at this point in the history
  • Loading branch information
pombredanne committed Dec 20, 2017
2 parents ee3e335 + 116c5d6 commit 34c4d5f
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@ ENV/
#PyCharm

.idea/
/tmp/
34 changes: 1 addition & 33 deletions fs/_fscompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,8 @@
try:
from os import fsencode, fsdecode
except ImportError:
def _fscodec():
encoding = sys.getfilesystemencoding()
errors = 'strict' if encoding == 'mbcs' else 'surrogateescape'
from backports.os import fsencode, fsdecode

def fsencode(filename):
"""
Encode filename to the filesystem encoding with 'surrogateescape' error
handler, return bytes unchanged. On Windows, use 'strict' error handler if
the file system encoding is 'mbcs' (which is the default encoding).
"""
if isinstance(filename, bytes):
return filename
elif isinstance(filename, six.text_type):
return filename.encode(encoding, errors)
else:
raise TypeError("expect string type, not %s" % type(filename).__name__)

def fsdecode(filename):
"""
Decode filename from the filesystem encoding with 'surrogateescape' error
handler, return str unchanged. On Windows, use 'strict' error handler if
the file system encoding is 'mbcs' (which is the default encoding).
"""
if isinstance(filename, six.text_type):
return filename
elif isinstance(filename, bytes):
return filename.decode(encoding, errors)
else:
raise TypeError("expect string type, not %s" % type(filename).__name__)

return fsencode, fsdecode

fsencode, fsdecode = _fscodec()
del _fscodec

try:
from os import fspath
Expand Down
6 changes: 4 additions & 2 deletions fs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,16 @@ def getsize(self, path):
size = self.getdetails(path).size
return size

def getsyspath(self, path):
def getsyspath(self, path, as_bytes=False):
"""Get the *system path* of a resource.
Parameters:
path (str): A path on the filesystem.
as_bytes (bool, optional): If `True`, return the path as bytes using
the native filesystem encoding. (defaults to `False`).
Returns:
str: the *system path* of the resource, if any.
str: the *system path* of the resource, if any, always as Unicode.
Raises:
fs.errors.NoSysPath: If there is no corresponding system path.
Expand Down
Loading

0 comments on commit 34c4d5f

Please sign in to comment.