summaryrefslogtreecommitdiff
path: root/xattr
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2018-01-28 12:11:37 -0800
committerBob Ippolito <bob@redivi.com>2018-01-28 12:11:37 -0800
commita8bf7c73a1d5bf0f3046fe5296d8d47e1b4570d6 (patch)
treea2affcb892b6ae5207f3739c0b97d5126ef9f888 /xattr
parent85182252f837b0c370b450ee2d83ed04023ef7b3 (diff)
downloadxattr-a8bf7c73a1d5bf0f3046fe5296d8d47e1b4570d6.tar.gz
prep for 0.9.3
Diffstat (limited to 'xattr')
-rw-r--r--xattr/__init__.py2
-rw-r--r--xattr/compat.py20
-rw-r--r--xattr/lib.py17
3 files changed, 23 insertions, 16 deletions
diff --git a/xattr/__init__.py b/xattr/__init__.py
index 6e605bd..651d542 100644
--- a/xattr/__init__.py
+++ b/xattr/__init__.py
@@ -7,7 +7,7 @@ The xattr type wraps a path or file descriptor with a dict-like interface
that exposes these extended attributes.
"""
-__version__ = '0.9.2'
+__version__ = '0.9.3'
from .compat import integer_types
from .lib import (XATTR_NOFOLLOW, XATTR_CREATE, XATTR_REPLACE,
diff --git a/xattr/compat.py b/xattr/compat.py
index b3094e3..16fbccc 100644
--- a/xattr/compat.py
+++ b/xattr/compat.py
@@ -1,6 +1,9 @@
"""Python 3 compatibility shims
"""
+import os
import sys
+import codecs
+
if sys.version_info[0] < 3:
integer_types = (int, long)
text_type = unicode
@@ -9,3 +12,20 @@ else:
integer_types = (int,)
text_type = str
binary_type = bytes
+
+fs_encoding = sys.getfilesystemencoding()
+fs_errors = 'strict'
+if fs_encoding != 'mbcs':
+ try:
+ codecs.lookup('surrogateescape')
+ fs_errors = 'surrogateescape'
+ except LookupError:
+ pass
+try:
+ fs_encode = os.fsencode
+except AttributeError:
+ def fs_encode(val):
+ if not isinstance(val, bytes):
+ return val.encode(fs_encoding, fs_errors)
+ else:
+ return val
diff --git a/xattr/lib.py b/xattr/lib.py
index 46f61dc..9221b40 100644
--- a/xattr/lib.py
+++ b/xattr/lib.py
@@ -1,6 +1,8 @@
import os
import sys
+import .compat import fs_encode
+
try:
from ._lib import lib, ffi
except ImportError:
@@ -16,21 +18,6 @@ XATTR_MAXNAMELEN = lib.XATTR_MAXNAMELEN
XATTR_FINDERINFO_NAME = "com.apple.FinderInfo"
XATTR_RESOURCEFORK_NAME = "com.apple.ResourceFork"
-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):
if not isinstance(val, bytes):