Python os.removexattr() Examples
The following are 14
code examples of os.removexattr().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: test_os.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def _check_xattrs_str(self, s, getxattr, setxattr, removexattr, listxattr, **kwargs): fn = support.TESTFN open(fn, "wb").close() with self.assertRaises(OSError) as cm: getxattr(fn, s("user.test"), **kwargs) self.assertEqual(cm.exception.errno, errno.ENODATA) init_xattr = listxattr(fn) self.assertIsInstance(init_xattr, list) setxattr(fn, s("user.test"), b"", **kwargs) xattr = set(init_xattr) xattr.add("user.test") self.assertEqual(set(listxattr(fn)), xattr) self.assertEqual(getxattr(fn, b"user.test", **kwargs), b"") setxattr(fn, s("user.test"), b"hello", os.XATTR_REPLACE, **kwargs) self.assertEqual(getxattr(fn, b"user.test", **kwargs), b"hello") with self.assertRaises(OSError) as cm: setxattr(fn, s("user.test"), b"bye", os.XATTR_CREATE, **kwargs) self.assertEqual(cm.exception.errno, errno.EEXIST) with self.assertRaises(OSError) as cm: setxattr(fn, s("user.test2"), b"bye", os.XATTR_REPLACE, **kwargs) self.assertEqual(cm.exception.errno, errno.ENODATA) setxattr(fn, s("user.test2"), b"foo", os.XATTR_CREATE, **kwargs) xattr.add("user.test2") self.assertEqual(set(listxattr(fn)), xattr) removexattr(fn, s("user.test"), **kwargs) with self.assertRaises(OSError) as cm: getxattr(fn, s("user.test"), **kwargs) self.assertEqual(cm.exception.errno, errno.ENODATA) xattr.remove("user.test") self.assertEqual(set(listxattr(fn)), xattr) self.assertEqual(getxattr(fn, s("user.test2"), **kwargs), b"foo") setxattr(fn, s("user.test"), b"a"*1024, **kwargs) self.assertEqual(getxattr(fn, s("user.test"), **kwargs), b"a"*1024) removexattr(fn, s("user.test"), **kwargs) many = sorted("user.test{}".format(i) for i in range(100)) for thing in many: setxattr(fn, thing, b"x", **kwargs) self.assertEqual(set(listxattr(fn)), set(init_xattr) | set(many))
Example #2
Source File: test_os.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_simple(self): self._check_xattrs(os.getxattr, os.setxattr, os.removexattr, os.listxattr)
Example #3
Source File: test_os.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_lpath(self): self._check_xattrs(os.getxattr, os.setxattr, os.removexattr, os.listxattr, follow_symlinks=False)
Example #4
Source File: test_os.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_fds(self): def getxattr(path, *args): with open(path, "rb") as fp: return os.getxattr(fp.fileno(), *args) def setxattr(path, *args): with open(path, "wb") as fp: os.setxattr(fp.fileno(), *args) def removexattr(path, *args): with open(path, "wb") as fp: os.removexattr(fp.fileno(), *args) def listxattr(path, *args): with open(path, "rb") as fp: return os.listxattr(fp.fileno(), *args) self._check_xattrs(getxattr, setxattr, removexattr, listxattr)
Example #5
Source File: test_os.py From ironpython3 with Apache License 2.0 | 5 votes |
def _check_xattrs_str(self, s, getxattr, setxattr, removexattr, listxattr, **kwargs): fn = support.TESTFN open(fn, "wb").close() with self.assertRaises(OSError) as cm: getxattr(fn, s("user.test"), **kwargs) self.assertEqual(cm.exception.errno, errno.ENODATA) init_xattr = listxattr(fn) self.assertIsInstance(init_xattr, list) setxattr(fn, s("user.test"), b"", **kwargs) xattr = set(init_xattr) xattr.add("user.test") self.assertEqual(set(listxattr(fn)), xattr) self.assertEqual(getxattr(fn, b"user.test", **kwargs), b"") setxattr(fn, s("user.test"), b"hello", os.XATTR_REPLACE, **kwargs) self.assertEqual(getxattr(fn, b"user.test", **kwargs), b"hello") with self.assertRaises(OSError) as cm: setxattr(fn, s("user.test"), b"bye", os.XATTR_CREATE, **kwargs) self.assertEqual(cm.exception.errno, errno.EEXIST) with self.assertRaises(OSError) as cm: setxattr(fn, s("user.test2"), b"bye", os.XATTR_REPLACE, **kwargs) self.assertEqual(cm.exception.errno, errno.ENODATA) setxattr(fn, s("user.test2"), b"foo", os.XATTR_CREATE, **kwargs) xattr.add("user.test2") self.assertEqual(set(listxattr(fn)), xattr) removexattr(fn, s("user.test"), **kwargs) with self.assertRaises(OSError) as cm: getxattr(fn, s("user.test"), **kwargs) self.assertEqual(cm.exception.errno, errno.ENODATA) xattr.remove("user.test") self.assertEqual(set(listxattr(fn)), xattr) self.assertEqual(getxattr(fn, s("user.test2"), **kwargs), b"foo") setxattr(fn, s("user.test"), b"a"*1024, **kwargs) self.assertEqual(getxattr(fn, s("user.test"), **kwargs), b"a"*1024) removexattr(fn, s("user.test"), **kwargs) many = sorted("user.test{}".format(i) for i in range(100)) for thing in many: setxattr(fn, thing, b"x", **kwargs) self.assertEqual(set(listxattr(fn)), set(init_xattr) | set(many))
Example #6
Source File: test_os.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_simple(self): self._check_xattrs(os.getxattr, os.setxattr, os.removexattr, os.listxattr)
Example #7
Source File: test_os.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_lpath(self): self._check_xattrs(os.getxattr, os.setxattr, os.removexattr, os.listxattr, follow_symlinks=False)
Example #8
Source File: test_os.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_fds(self): def getxattr(path, *args): with open(path, "rb") as fp: return os.getxattr(fp.fileno(), *args) def setxattr(path, *args): with open(path, "wb") as fp: os.setxattr(fp.fileno(), *args) def removexattr(path, *args): with open(path, "wb") as fp: os.removexattr(fp.fileno(), *args) def listxattr(path, *args): with open(path, "rb") as fp: return os.listxattr(fp.fileno(), *args) self._check_xattrs(getxattr, setxattr, removexattr, listxattr)
Example #9
Source File: localiface.py From wopiserver with Apache License 2.0 | 5 votes |
def rmxattr(_endpoint, filepath, _userid, key): '''Remove the extended attribute <key> on behalf of the given userid''' try: os.removexattr(_getfilepath(filepath), 'user.' + key) except (FileNotFoundError, PermissionError, OSError) as e: log.warning('msg="Failed to rmxattr" filepath="%s" key="%s" exception="%s"' % (filepath, key, e)) raise IOError(e)
Example #10
Source File: test_os.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def _check_xattrs_str(self, s, getxattr, setxattr, removexattr, listxattr, **kwargs): fn = support.TESTFN open(fn, "wb").close() with self.assertRaises(OSError) as cm: getxattr(fn, s("user.test"), **kwargs) self.assertEqual(cm.exception.errno, errno.ENODATA) init_xattr = listxattr(fn) self.assertIsInstance(init_xattr, list) setxattr(fn, s("user.test"), b"", **kwargs) xattr = set(init_xattr) xattr.add("user.test") self.assertEqual(set(listxattr(fn)), xattr) self.assertEqual(getxattr(fn, b"user.test", **kwargs), b"") setxattr(fn, s("user.test"), b"hello", os.XATTR_REPLACE, **kwargs) self.assertEqual(getxattr(fn, b"user.test", **kwargs), b"hello") with self.assertRaises(OSError) as cm: setxattr(fn, s("user.test"), b"bye", os.XATTR_CREATE, **kwargs) self.assertEqual(cm.exception.errno, errno.EEXIST) with self.assertRaises(OSError) as cm: setxattr(fn, s("user.test2"), b"bye", os.XATTR_REPLACE, **kwargs) self.assertEqual(cm.exception.errno, errno.ENODATA) setxattr(fn, s("user.test2"), b"foo", os.XATTR_CREATE, **kwargs) xattr.add("user.test2") self.assertEqual(set(listxattr(fn)), xattr) removexattr(fn, s("user.test"), **kwargs) with self.assertRaises(OSError) as cm: getxattr(fn, s("user.test"), **kwargs) self.assertEqual(cm.exception.errno, errno.ENODATA) xattr.remove("user.test") self.assertEqual(set(listxattr(fn)), xattr) self.assertEqual(getxattr(fn, s("user.test2"), **kwargs), b"foo") setxattr(fn, s("user.test"), b"a"*1024, **kwargs) self.assertEqual(getxattr(fn, s("user.test"), **kwargs), b"a"*1024) removexattr(fn, s("user.test"), **kwargs) many = sorted("user.test{}".format(i) for i in range(100)) for thing in many: setxattr(fn, thing, b"x", **kwargs) self.assertEqual(set(listxattr(fn)), set(init_xattr) | set(many))
Example #11
Source File: test_os.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_simple(self): self._check_xattrs(os.getxattr, os.setxattr, os.removexattr, os.listxattr)
Example #12
Source File: test_os.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_lpath(self): self._check_xattrs(os.getxattr, os.setxattr, os.removexattr, os.listxattr, follow_symlinks=False)
Example #13
Source File: test_os.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_fds(self): def getxattr(path, *args): with open(path, "rb") as fp: return os.getxattr(fp.fileno(), *args) def setxattr(path, *args): with open(path, "wb") as fp: os.setxattr(fp.fileno(), *args) def removexattr(path, *args): with open(path, "wb") as fp: os.removexattr(fp.fileno(), *args) def listxattr(path, *args): with open(path, "rb") as fp: return os.listxattr(fp.fileno(), *args) self._check_xattrs(getxattr, setxattr, removexattr, listxattr)
Example #14
Source File: file.py From code with MIT License | 5 votes |
def set_file_attr(path, attr, value): try: if hasattr(path, "fileno"): path = path.fileno() if hasattr(value, "encode"): value = value.encode("utf-8") if value: os.setxattr(path, "user.%s" % attr, value) else: os.removexattr(path, "user.%s" % attr) except FileNotFoundError: raise except OSError: return