summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Augier <max@xolus.net>2016-02-23 16:03:42 +0100
committerMaxime Augier <max@xolus.net>2016-02-23 16:03:42 +0100
commitfb89a316c6ff1ef45fe7315e16497fb02a2a54d9 (patch)
treef59c11d2daaf33a1eb2d86c7f81e035cb4bcd66c
parent6cf6290eed28e45539fd31f5cb01cfd3257da477 (diff)
downloadxattr-fb89a316c6ff1ef45fe7315e16497fb02a2a54d9.tar.gz
Use surrogate handling identical to recent python's os.fsencode
-rw-r--r--xattr/lib.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/xattr/lib.py b/xattr/lib.py
index 0f29190..6b098ff 100644
--- a/xattr/lib.py
+++ b/xattr/lib.py
@@ -608,8 +608,14 @@ 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(sys.getfilesystemencoding())
+ return val.encode(encoding, errors)
else:
return val