summaryrefslogtreecommitdiff
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
parent85182252f837b0c370b450ee2d83ed04023ef7b3 (diff)
downloadxattr-a8bf7c73a1d5bf0f3046fe5296d8d47e1b4570d6.tar.gz
prep for 0.9.3
-rw-r--r--CHANGES.txt5
-rw-r--r--setup.py2
-rw-r--r--xattr/__init__.py2
-rw-r--r--xattr/compat.py20
-rw-r--r--xattr/lib.py17
5 files changed, 29 insertions, 17 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index e1d4141..cc99da7 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,8 @@
+Version 0.9.3 released 2018-01-28
+
+* Do not attempt to use surrogateescape unless it is available
+ https://github.com/xattr/xattr/issues/59
+
Version 0.9.2 released 2017-04-02
* Fix BSD issue w/ lsattr and long attrs
diff --git a/setup.py b/setup.py
index 4efafa0..a643a47 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ import sys
from setuptools import setup
-VERSION = '0.9.2'
+VERSION = '0.9.3'
DESCRIPTION = "Python wrapper for extended filesystem attributes"
LONG_DESCRIPTION = """
Extended attributes extend the basic attributes of files and directories
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):