diff options
-rw-r--r-- | CHANGES.txt | 5 | ||||
-rw-r--r-- | xattr/__init__.py | 5 | ||||
-rw-r--r-- | xattr/compat.py | 11 | ||||
-rw-r--r-- | xattr/pyxattr_compat.py | 7 |
4 files changed, 23 insertions, 5 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 07ca7d0..1734b00 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,8 @@ +Version 0.9.0 released XXXX-XX-XX + +* Allow (Python 2) long for fd + https://github.com/xattr/xattr/pull/51 + Version 0.8.0 released 2016-02-28 * Use os.fsencode where available to better handle filesystem quirks related diff --git a/xattr/__init__.py b/xattr/__init__.py index dad8e5a..57a771e 100644 --- a/xattr/__init__.py +++ b/xattr/__init__.py @@ -9,6 +9,7 @@ that exposes these extended attributes. __version__ = '0.8.0' +from .compat import integer_types from .lib import (XATTR_NOFOLLOW, XATTR_CREATE, XATTR_REPLACE, XATTR_NOSECURITY, XATTR_MAXNAMELEN, XATTR_FINDERINFO_NAME, XATTR_RESOURCEFORK_NAME, _getxattr, _fgetxattr, _setxattr, _fsetxattr, @@ -46,14 +47,14 @@ class xattr(object): self.value = obj def __repr__(self): - if isinstance(self.value, int): + if isinstance(self.value, integer_types): flavor = "fd" else: flavor = "file" return "<%s %s=%r>" % (type(self).__name__, flavor, self.value) def _call(self, name_func, fd_func, *args): - if isinstance(self.value, int): + if isinstance(self.value, integer_types): return fd_func(self.value, *args) else: return name_func(self.value, *args) diff --git a/xattr/compat.py b/xattr/compat.py new file mode 100644 index 0000000..b3094e3 --- /dev/null +++ b/xattr/compat.py @@ -0,0 +1,11 @@ +"""Python 3 compatibility shims +""" +import sys +if sys.version_info[0] < 3: + integer_types = (int, long) + text_type = unicode + binary_type = str +else: + integer_types = (int,) + text_type = str + binary_type = bytes diff --git a/xattr/pyxattr_compat.py b/xattr/pyxattr_compat.py index 0ef913b..3d594de 100644 --- a/xattr/pyxattr_compat.py +++ b/xattr/pyxattr_compat.py @@ -8,6 +8,7 @@ This module provides compatibility for the pyxattr API. import sys +from .compat import (binary_type, integer_types, text_type) from .lib import (XATTR_NOFOLLOW, XATTR_CREATE, XATTR_REPLACE, XATTR_NOSECURITY, XATTR_MAXNAMELEN, XATTR_FINDERINFO_NAME, XATTR_RESOURCEFORK_NAME, _getxattr, _fgetxattr, _setxattr, _fsetxattr, @@ -29,13 +30,13 @@ _NO_NS = object() _fsencoding = sys.getfilesystemencoding() def _call(item, name_func, fd_func, *args): - if isinstance(item, int): + if isinstance(item, integer_types): return fd_func(item, *args) elif hasattr(item, 'fileno'): return fd_func(item.fileno(), *args) - elif isinstance(item, str): + elif isinstance(item, binary_type): return name_func(item, *args) - elif isinstance(item, unicode): + elif isinstance(item, text_type): item = item.encode(_fsencoding) return name_func(item, *args) else: |