File: xattrs.py

package info (click to toggle)
python-fs 0.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,452 kB
  • ctags: 2,991
  • sloc: python: 20,659; makefile: 5
file content (73 lines) | stat: -rw-r--r-- 1,689 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
fs.osfs.xattrs
==============

Extended-attribute support for OSFS

"""


import os
import sys
import errno

from fs.errors import *
from fs.path import *
from fs.base import FS

try:
    import xattr
except ImportError:
    xattr = None


if xattr is not None:

    class OSFSXAttrMixin(object):
        """Mixin providing extended-attribute support via the 'xattr' module"""

        def __init__(self, *args, **kwargs):
            super(OSFSXAttrMixin, self).__init__(*args, **kwargs)

        @convert_os_errors
        def setxattr(self, path, key, value):
            xattr.xattr(self.getsyspath(path))[key]=value

        @convert_os_errors
        def getxattr(self, path, key, default=None):
            try:
                return xattr.xattr(self.getsyspath(path)).get(key)
            except KeyError:
                return default

        @convert_os_errors
        def delxattr(self, path, key):
            try:
                del xattr.xattr(self.getsyspath(path))[key]
            except KeyError:
                pass

        @convert_os_errors
        def listxattrs(self, path):
            return xattr.xattr(self.getsyspath(path)).keys()

else:

    class OSFSXAttrMixin(object):
        """Mixin disable extended-attribute support."""

        def __init__(self, *args, **kwargs):
            super(OSFSXAttrMixin, self).__init__(*args, **kwargs)

        def getxattr(self,path,key,default=None):
            raise UnsupportedError

        def setxattr(self,path,key,value):
            raise UnsupportedError

        def delxattr(self,path,key):
            raise UnsupportedError

        def listxattrs(self,path):
            raise UnsupportedError