diff options
author | Maxime Augier <max@xolus.net> | 2016-02-23 21:31:43 +0100 |
---|---|---|
committer | Maxime Augier <max@xolus.net> | 2016-02-23 21:31:43 +0100 |
commit | b2967daa6f71d2cddf784e03b4a91ccc9de104de (patch) | |
tree | 0caf7002f65c89fae2e6a8af486ad2d6a1746ca0 | |
parent | fb89a316c6ff1ef45fe7315e16497fb02a2a54d9 (diff) | |
download | xattr-b2967daa6f71d2cddf784e03b4a91ccc9de104de.tar.gz |
Use os.fsencode if available
-rw-r--r-- | xattr/lib.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/xattr/lib.py b/xattr/lib.py index 6b098ff..1df1386 100644 --- a/xattr/lib.py +++ b/xattr/lib.py @@ -606,18 +606,20 @@ XATTR_MAXNAMELEN = lib.XATTR_MAXNAMELEN XATTR_FINDERINFO_NAME = "com.apple.FinderInfo" XATTR_RESOURCEFORK_NAME = "com.apple.ResourceFork" - -def fs_encode(val): - encoding = sys.getfilesystemencoding() - if encoding == 'mbcs': - errors = 'strict' - else: - errors = 'surrogateescape' - - if not isinstance(val, bytes): - return val.encode(encoding, errors) - else: - return val +try: + fs_encode = os.fsencode +except AttributeError: + def fs_encode(val): + encoding = sys.getfilesystemencoding() + if encoding == 'mbcs': + errors = 'strict' + else: + errors = 'surrogateescape' + + if not isinstance(val, bytes): + return val.encode(encoding, errors) + else: + return val def _check_bytes(val): |